3v4l.org

run code in 200+ PHP versions simultaneously
<?php $a = []; $keys = [ 'array' => [], 'object' => new stdClass, 'closure' => function () {}, 'class' => new class {}, 'class with tostring' => new class {function __toString(){return 'to string class';}}, 'resource' => fopen(__FILE__, 'r'), ]; foreach ($keys as $desc =>$key) { echo "===" . $desc . "===\n"; $a[$key] = true; echo "state of array: \n"; var_dump($a); echo "state of key: \n"; var_dump($key); echo "is the key set in the array: \n"; var_dump(isset($a[$key])); } echo "===============\n"; var_dump($a);
based on 3lpob
Output for 7.0.0 - 7.4.0
===array=== Warning: Illegal offset type in /in/cQ8hf on line 16 state of array: array(0) { } state of key: array(0) { } is the key set in the array: Warning: Illegal offset type in isset or empty in /in/cQ8hf on line 22 bool(false) ===object=== Warning: Illegal offset type in /in/cQ8hf on line 16 state of array: array(0) { } state of key: object(stdClass)#1 (0) { } is the key set in the array: Warning: Illegal offset type in isset or empty in /in/cQ8hf on line 22 bool(false) ===closure=== Warning: Illegal offset type in /in/cQ8hf on line 16 state of array: array(0) { } state of key: object(Closure)#2 (0) { } is the key set in the array: Warning: Illegal offset type in isset or empty in /in/cQ8hf on line 22 bool(false) ===class=== Warning: Illegal offset type in /in/cQ8hf on line 16 state of array: array(0) { } state of key: object(class@anonymous)#3 (0) { } is the key set in the array: Warning: Illegal offset type in isset or empty in /in/cQ8hf on line 22 bool(false) ===class with tostring=== Warning: Illegal offset type in /in/cQ8hf on line 16 state of array: array(0) { } state of key: object(class@anonymous)#4 (0) { } is the key set in the array: Warning: Illegal offset type in isset or empty in /in/cQ8hf on line 22 bool(false) ===resource=== Notice: Resource ID#5 used as offset, casting to integer (5) in /in/cQ8hf on line 16 state of array: array(1) { [5]=> bool(true) } state of key: resource(5) of type (stream) is the key set in the array: bool(true) =============== array(1) { [5]=> bool(true) }
Output for 5.4.0 - 5.6.40
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/cQ8hf on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/cQ8hf on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/cQ8hf on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/cQ8hf on line 3
Process exited with code 255.