3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SerialDateTime extends DateTime implements JsonSerializable{ public function jsonSerialize(){ return $this->getTimestamp(); } } class StringDateTime extends DateTime{ public function __toString(){ return ''+$this->getTimestamp(); } } $j = new SerialDateTime; $s = new StringDateTime; //echo $j."\n"; echo $s."\n"; echo json_encode(array($j, $s));

preferences:
35.39 ms | 402 KiB | 5 Q