3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExtendedArrayObject extends ArrayObject { function offsetGet($offset) { echo "Called", PHP_EOL; return parent::offsetGet($offset, $array); } } class ExtendedArrayAccess implements ArrayAccess { private $data = array(); function __construct(array $array = array()) { $this->data = $array; } function offsetExists($offset) { return array_key_exists($offset, $this->data); } function offsetGet($offset) { return $this->data[$offset]; } function offsetSet($offset, $value) { $this->data[$offset] = $value; } function offsetUnset($offset) { unset($this->data[$offset]); } } $inputs = array( 'array' => array(), 'ExtendedArrayObject' => new ExtendedArrayObject(), 'ExtendedArrayAccess' => new ExtendedArrayAccess(), ); class Tests { function test_existing_key_with_not_empty_value($array) { $array['foo'] = 1; $this->expect(isset($array['foo']) === true, __FUNCTION__, $array); $this->expect(empty($array['foo']) === false, __FUNCTION__, $array); } function test_existing_key_with_empty_value($array) { $array['foo'] = 0; $this->expect(isset($array['foo']) === true, __FUNCTION__, $array); $this->expect(empty($array['foo']) === true, __FUNCTION__, $array); } function test_non_existent_key($array) { $this->expect(isset($array['foo']) === true, __FUNCTION__, $array); $this->expect(empty($array['foo']) === false, __FUNCTION__, $array); } function test_existing_key_with_null_value($array) { $array['foo'] = null; $this->expect(isset($array['foo']) === false, __FUNCTION__, $array); $this->expect(empty($array['foo']) === true, __FUNCTION__, $array); } private function getType($v) { return is_array($v) ? 'array' : get_class($v); } private function expect($condition, $function, $array) { if (!$condition) { echo $this->getType($array), ' failed ', $function, PHP_EOL; } } } $tests = new Tests; foreach (get_class_methods($tests) as $test) { foreach ($inputs as $structure) { $tests->$test($structure); } }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of ExtendedArrayObject::offsetGet($offset) should either be compatible with ArrayObject::offsetGet(mixed $key): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7sTlX on line 4 Deprecated: Return type of ExtendedArrayAccess::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7sTlX on line 15 Deprecated: Return type of ExtendedArrayAccess::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7sTlX on line 18 Deprecated: Return type of ExtendedArrayAccess::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7sTlX on line 21 Deprecated: Return type of ExtendedArrayAccess::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7sTlX on line 24 Called Warning: Undefined variable $array in /in/7sTlX on line 6 Fatal error: Uncaught ArgumentCountError: ArrayObject::offsetGet() expects exactly 1 argument, 2 given in /in/7sTlX:6 Stack trace: #0 /in/7sTlX(6): ArrayObject->offsetGet('foo', NULL) #1 /in/7sTlX(39): ExtendedArrayObject->offsetGet('foo') #2 /in/7sTlX(73): Tests->test_existing_key_with_not_empty_value(Object(ExtendedArrayObject)) #3 {main} thrown in /in/7sTlX on line 6
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.45 ms | 403 KiB | 8 Q