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
Warning: A non-numeric value encountered in /in/Ba0rr on line 13 Recoverable fatal error: Method StringDateTime::__toString() must return a string value in /in/Ba0rr on line 21
Process exited with code 255.
Output for 5.4.0 - 7.0.14
Catchable fatal error: Method StringDateTime::__toString() must return a string value in /in/Ba0rr on line 21
Process exited with code 255.
Output for 5.2.0 - 5.3.29
Fatal error: Interface 'JsonSerializable' not found in /in/Ba0rr on line 3
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/Ba0rr 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/Ba0rr 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/Ba0rr on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/Ba0rr on line 3
Process exited with code 255.