3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements \JsonSerializable { private $test; public function __construct(int $test) { $this->test = $test; } public function getTest(): int { return $this->test; } public function jsonSerialize(): array { $clone = new \stdClass; $clone->test = $this->getTest(); return (array) $clone; } } $testClass = new Test(1); $stdClass = new \stdClass; $stdClass->test = 1; $testClassEncode = json_encode($testClass); $stdClassEncode = json_encode((array) $stdClass); var_dump($testClassEncode, $stdClassEncode);
Output for 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(10) "{"test":1}" string(10) "{"test":1}"
Output for 5.6.38
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/dM8Y1 on line 9
Process exited with code 255.

preferences:
101.98 ms | 1448 KiB | 4 Q