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(): mixed { return $this->array; } } $array = ['foo' => 'bar', 'quux' => 'baz']; echo json_encode(new ArrayValue($array), JSON_PRETTY_PRINT);
Output for 8.2.10 - 8.2.23, 8.3.0 - 8.3.11
Deprecated: Creation of dynamic property ArrayValue::$array is deprecated in /in/gqeus on line 5 { "foo": "bar", "quux": "baz" }
Output for 8.0.15, 8.1.2 - 8.1.29
{ "foo": "bar", "quux": "baz" }

preferences:
43.94 ms | 407 KiB | 5 Q