3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyArrayObject extends ArrayObject{ function __construct($input=[]){ parent::__construct($input); } function offsetSet($x,$v){ echo "offsetSet('{$x}')\n"; return parent::offsetSet($x,$v); } function offsetGet($x){ echo "offsetGet('{$x}')\n"; return parent::offsetGet($x); } function __get($x){ echo "__get('{$x}')\n"; } function __set($x,$v){ echo "__set('{$x}')\n"; } function offsetExists($x){ echo "offsetExists('{$x}')\n"; return parent::offsetExists($x); } } $x=new MyArrayObject; $x->hello=5; $x['hi']=10; $x['hello']++; @$x->a->b=7; $x->a->b++;
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 MyArrayObject::offsetExists($x) should either be compatible with ArrayObject::offsetExists(mixed $key): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZgSI8 on line 20 Deprecated: Return type of MyArrayObject::offsetGet($x) should either be compatible with ArrayObject::offsetGet(mixed $key): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZgSI8 on line 10 Deprecated: Return type of MyArrayObject::offsetSet($x, $v) 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/ZgSI8 on line 6 __set('hello') offsetSet('hi') offsetGet('hello') Warning: Undefined array key "hello" in /in/ZgSI8 on line 12 Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/ZgSI8 on line 28 __get('a') Fatal error: Uncaught Error: Attempt to assign property "b" on null in /in/ZgSI8:29 Stack trace: #0 {main} thrown in /in/ZgSI8 on line 29
Process exited with code 255.
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 MyArrayObject::offsetExists($x) should either be compatible with ArrayObject::offsetExists(mixed $key): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZgSI8 on line 20 Deprecated: Return type of MyArrayObject::offsetGet($x) should either be compatible with ArrayObject::offsetGet(mixed $key): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ZgSI8 on line 10 Deprecated: Return type of MyArrayObject::offsetSet($x, $v) 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/ZgSI8 on line 6 __set('hello') offsetSet('hi') offsetGet('hello') Warning: Undefined array key "hello" in /in/ZgSI8 on line 12 Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/ZgSI8 on line 28 __get('a') Fatal error: Uncaught Error: Attempt to assign property "b" on null in /in/ZgSI8:29 Stack trace: #0 {main} thrown in /in/ZgSI8 on line 29
Process exited with code 255.
Output for 8.0.0 - 8.0.30
__set('hello') offsetSet('hi') offsetGet('hello') Warning: Undefined array key "hello" in /in/ZgSI8 on line 12 Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/ZgSI8 on line 28 __get('a') Fatal error: Uncaught Error: Attempt to assign property "b" on null in /in/ZgSI8:29 Stack trace: #0 {main} thrown in /in/ZgSI8 on line 29
Process exited with code 255.
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.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
__set('hello') offsetSet('hi') offsetGet('hello') Notice: Undefined index: hello in /in/ZgSI8 on line 12 Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/ZgSI8 on line 28 __get('a') __get('a') Notice: Indirect modification of overloaded property MyArrayObject::$a has no effect in /in/ZgSI8 on line 30 Warning: Creating default object from empty value in /in/ZgSI8 on line 30 Notice: Undefined property: stdClass::$b in /in/ZgSI8 on line 30
Output for 7.3.32 - 7.3.33
__set('hello') offsetSet('hi') offsetGet('hello') __get('a') __get('a') Warning: Creating default object from empty value in /in/ZgSI8 on line 30

preferences:
211.35 ms | 401 KiB | 290 Q