3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyStuff extends ArrayObject { function offsetGet($offset) { echo "Called", PHP_EOL; return parent::offsetGet($offset); } } $array = array( 'foo' => 42, 'baz' => null, 'k' => 0, ); $array_object = new MyStuff($array); // existing key, non-null value: assert(isset($array['foo']) === true); assert(empty($array['foo']) === false); assert(isset($array_object['foo']) === true); assert(empty($array_object['foo']) === false); // non-existing key: assert(isset($array['bar']) === false); assert(empty($array['bar']) === true); assert(isset($array_object['bar']) === false); assert(empty($array_object['bar']) === true); // key where value is null: assert(isset($array['baz']) === false); assert(empty($array['baz']) === true); assert(isset($array_object['baz']) === false); assert(empty($array_object['baz']) === true); // key where value is 0: assert(isset($array['k']) === true); assert(empty($array['k']) === true); assert(isset($array_object['k']) === true); assert(empty($array_object['k']) === true);
Output for 5.6.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Called Called Called
Output for 5.3.11 - 5.3.29, 5.4.1 - 5.5.38
Output for 5.2.1 - 5.3.10, 5.4.0
Warning: assert(): Assertion failed in /in/M7tps on line 36
Output for 5.0.0 - 5.2.0
Warning: assert(): Assertion failed in /in/M7tps on line 36 Warning: assert(): Assertion failed in /in/M7tps on line 37 Warning: assert(): Assertion failed in /in/M7tps on line 44
Output for 4.3.2 - 4.4.9
Fatal error: Class mystuff: Cannot inherit from undefined class arrayobject in /in/M7tps on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Class mystuff: Cannot inherit from undefined class arrayobject in /in/M7tps on line 3