3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thing extends ArrayObject { public function __construct(array $data) { parent::__construct($data, self::ARRAY_AS_PROPS); } public function offsetSet($index, $value) { parent::offsetSet($index, $value); return $this; } public function offsetGet($index) { if ($this->offsetExists($index)) { return parent::offsetGet($index); } return null; } } $thing = new Thing([]); $thing->dynamic['key'] = ['is-set' => 'up to 7.1.3']; var_dump($thing);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of Thing::offsetGet($index) should either be compatible with ArrayObject::offsetGet(mixed $key): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/em3Sa on line 15 Deprecated: Return type of Thing::offsetSet($index, $value) should either be compatible with ArrayObject::offsetSet(mixed $key, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/em3Sa on line 10 object(Thing)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Return type of Thing::offsetGet($index) should either be compatible with ArrayObject::offsetGet(mixed $key): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/em3Sa on line 15 Deprecated: Return type of Thing::offsetSet($index, $value) should either be compatible with ArrayObject::offsetSet(mixed $key, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/em3Sa on line 10 object(Thing)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } }
Output for 7.1.4 - 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
object(Thing)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } }
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.3
object(Thing)#1 (1) { ["storage":"ArrayObject":private]=> array(1) { ["dynamic"]=> array(1) { ["key"]=> array(1) { ["is-set"]=> string(11) "up to 7.1.3" } } } }

preferences:
212.69 ms | 402 KiB | 291 Q