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 IIDcQ
Output for 7.1.25 - 7.4.0
===array=== Warning: Illegal offset type in /in/3lpob on line 16 state of array: \'narray(0) { } state of key: array(0) { } is the key set in the array: Warning: Illegal offset type in isset or empty in /in/3lpob on line 22 bool(false) ===object=== Warning: Illegal offset type in /in/3lpob on line 16 state of array: \'narray(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/3lpob on line 22 bool(false) ===closure=== Warning: Illegal offset type in /in/3lpob on line 16 state of array: \'narray(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/3lpob on line 22 bool(false) ===class=== Warning: Illegal offset type in /in/3lpob on line 16 state of array: \'narray(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/3lpob on line 22 bool(false) ===class with tostring=== Warning: Illegal offset type in /in/3lpob on line 16 state of array: \'narray(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/3lpob on line 22 bool(false) ===resource=== Notice: Resource ID#5 used as offset, casting to integer (5) in /in/3lpob on line 16 state of array: \'narray(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) }