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));
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of SerialDateTime::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Ba0rr on line 5 Fatal error: Uncaught TypeError: Unsupported operand types: string + int in /in/Ba0rr:13 Stack trace: #0 /in/Ba0rr(21): StringDateTime->__toString() #1 {main} thrown in /in/Ba0rr on line 13
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught TypeError: Unsupported operand types: string + int in /in/Ba0rr:13 Stack trace: #0 /in/Ba0rr(21): StringDateTime->__toString() #1 {main} thrown in /in/Ba0rr on line 13
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: A non-numeric value encountered in /in/Ba0rr on line 13 Fatal error: Uncaught Error: Method StringDateTime::__toString() must return a string value in /in/Ba0rr:21 Stack trace: #0 {main} thrown in /in/Ba0rr on line 21
Process exited with code 255.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
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 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20
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.2.17, 5.3.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.0.5, 5.1.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.3.11, 4.4.0 - 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.

preferences:
324.24 ms | 401 KiB | 370 Q