3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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));
Output for 7.1.0
1378912524 [1378912524,{"date":"2013-09-11 17:15:24.006191","timezone_type":3,"timezone":"Europe\/Amsterdam"}]
Output for 5.4.30 - 5.4.45, 5.5.14 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.14
1378912524 [1378912524,{"date":"2013-09-11 17:15:24.000000","timezone_type":3,"timezone":"Europe\/Amsterdam"}]
Output for 5.4.0 - 5.4.29, 5.5.0 - 5.5.13
1378912524 [1378912524,{"date":"2013-09-11 17:15:24","timezone_type":3,"timezone":"Europe\/Amsterdam"}]
Output for 5.2.0 - 5.3.29
Fatal error: Interface 'JsonSerializable' not found in /in/FaXks on line 3
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/FaXks on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/FaXks on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/FaXks on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/FaXks on line 3
Process exited with code 255.