3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.6.7 - 7.1.0
Called Notice: Undefined variable: array in /in/7sTlX on line 6 Warning: ArrayObject::offsetGet() expects exactly 1 parameter, 2 given in /in/7sTlX on line 6 ExtendedArrayObject failed test_existing_key_with_not_empty_value Called Notice: Undefined variable: array in /in/7sTlX on line 6 Warning: ArrayObject::offsetGet() expects exactly 1 parameter, 2 given in /in/7sTlX on line 6 array failed test_non_existent_key array failed test_non_existent_key Called Notice: Undefined variable: array in /in/7sTlX on line 6 Warning: ArrayObject::offsetGet() expects exactly 1 parameter, 2 given in /in/7sTlX on line 6 ExtendedArrayObject failed test_non_existent_key ExtendedArrayAccess failed test_non_existent_key Called Notice: Undefined variable: array in /in/7sTlX on line 6 Warning: ArrayObject::offsetGet() expects exactly 1 parameter, 2 given in /in/7sTlX on line 6 ExtendedArrayAccess failed test_existing_key_with_null_value
Output for 5.3.11 - 5.3.29, 5.4.1 - 5.5.35
array failed test_non_existent_key array failed test_non_existent_key ExtendedArrayObject failed test_non_existent_key ExtendedArrayAccess failed test_non_existent_key ExtendedArrayAccess failed test_existing_key_with_null_value
Output for 5.2.1 - 5.3.10, 5.4.0
array failed test_non_existent_key array failed test_non_existent_key ExtendedArrayObject failed test_non_existent_key ExtendedArrayAccess failed test_non_existent_key ExtendedArrayObject failed test_existing_key_with_null_value ExtendedArrayAccess failed test_existing_key_with_null_value
Output for 5.1.0 - 5.2.0
ExtendedArrayObject failed test_existing_key_with_empty_value array failed test_non_existent_key array failed test_non_existent_key ExtendedArrayAccess failed test_non_existent_key ExtendedArrayObject failed test_existing_key_with_null_value ExtendedArrayObject failed test_existing_key_with_null_value ExtendedArrayAccess failed test_existing_key_with_null_value
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/7sTlX on line 12
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/7sTlX on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/7sTlX on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/7sTlX on line 10
Process exited with code 255.