<?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));
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.
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.