3v4l.org

run code in 300+ 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);
Output for 8.3.0 - 8.3.4, 8.3.6
===array=== Fatal error: Uncaught TypeError: Cannot access offset of type array on array in /in/3lpob:16 Stack trace: #0 {main} thrown in /in/3lpob on line 16
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 ===array=== Fatal error: Uncaught TypeError: Cannot access offset of type array on array in /in/3lpob:16 Stack trace: #0 {main} thrown in /in/3lpob on line 16
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
===array=== Fatal error: Uncaught TypeError: Illegal offset type in /in/3lpob:16 Stack trace: #0 {main} thrown in /in/3lpob on line 16
Process exited with code 255.
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
===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) }
Output for 7.3.32, 7.4.26
===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=== 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) }

preferences:
172.38 ms | 404 KiB | 182 Q