3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayValue implements JsonSerializable { public function __construct(array $array) { $this->array = $array; } public function jsonSerialize() { return $this->array; } } $array = ['foo' => 'bar', 'quux' => 'baz']; echo json_encode(new ArrayValue($array), JSON_PRETTY_PRINT);
Output for 8.2.0 - 8.2.23, 8.3.0 - 8.3.12
Deprecated: Return type of ArrayValue::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Fon9f on line 8 Deprecated: Creation of dynamic property ArrayValue::$array is deprecated in /in/Fon9f on line 5 { "foo": "bar", "quux": "baz" }
Output for 8.1.0 - 8.1.29
Deprecated: Return type of ArrayValue::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Fon9f on line 8 { "foo": "bar", "quux": "baz" }
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
{ "foo": "bar", "quux": "baz" }

preferences:
63.07 ms | 410 KiB | 5 Q