3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyArrayObject extends ArrayObject{ function __construct($input=[]){ parent::__construct($input,ArrayObject::ARRAY_AS_PROPS); } 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
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/DJH6M 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/DJH6M 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/DJH6M on line 6 offsetSet('hello') offsetSet('hi') offsetGet('hello') Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/DJH6M on line 28 offsetGet('a') Fatal error: Uncaught Error: Attempt to assign property "b" on null in /in/DJH6M:29 Stack trace: #0 {main} thrown in /in/DJH6M on line 29
Process exited with code 255.
Output for 8.0.0 - 8.0.30
offsetSet('hello') offsetSet('hi') offsetGet('hello') Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/DJH6M on line 28 offsetGet('a') Fatal error: Uncaught Error: Attempt to assign property "b" on null in /in/DJH6M:29 Stack trace: #0 {main} thrown in /in/DJH6M on line 29
Process exited with code 255.
Output for 7.1.4 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
offsetSet('hello') offsetSet('hi') offsetGet('hello') Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/DJH6M on line 28 offsetGet('a') offsetGet('a') Notice: Undefined index: a in /in/DJH6M on line 12 Warning: Creating default object from empty value in /in/DJH6M on line 30 Notice: Undefined property: stdClass::$b in /in/DJH6M on line 30
Output for 7.3.32 - 7.3.33
offsetSet('hello') offsetSet('hi') offsetGet('hello') offsetGet('a') offsetGet('a') Warning: Creating default object from empty value in /in/DJH6M on line 30
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.3
offsetSet('hello') offsetSet('hi') offsetGet('hello') Notice: Indirect modification of overloaded element of MyArrayObject has no effect in /in/DJH6M on line 28

preferences:
222.18 ms | 402 KiB | 283 Q