3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A implements JsonSerializable{ public $baz = 10; function jsonSerialize(){ return ['bar' => 20]; } } class B implements JsonSerializable{ function jsonSerialize(){ return ['foo' => new A]; } } echo json_encode(new B, JSON_PRETTY_PRINT);
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Deprecated: Return type of A::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XTWcj on line 5 Deprecated: Return type of B::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XTWcj on line 11 { "foo": { "bar": 20 } }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
{ "foo": { "bar": 20 } }

preferences:
99.49 ms | 409 KiB | 5 Q