3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array('a' => 'aa'); $x = new ArrayObject; $x[null] = array(); $x[null]['bar'] = 'foo'; ### this causes it # ---------------------------------------- function f($k) { $f = array('f' => 'ff'); return $f[$k]; } echo "ArrayObject dump:\n"; var_dump($x); echo "Non-existing array elements (current scope, function scope)\n"; var_dump($a['b'], f('b')); echo "Define a new variable: \$s='hohohoooo'\n"; $s = 'hohohoooo'; var_dump($a['b'], f('b')); echo "Define a new variable: \$n=1\n"; $n = 1; var_dump($a['b'], f('b'));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
ArrayObject dump: object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(2) { [0]=> array(0) { } [""]=> array(1) { ["bar"]=> string(3) "foo" } } } Non-existing array elements (current scope, function scope) Warning: Undefined array key "b" in /in/p0fnK on line 20 Warning: Undefined array key "b" in /in/p0fnK on line 13 NULL NULL Define a new variable: $s='hohohoooo' Warning: Undefined array key "b" in /in/p0fnK on line 24 Warning: Undefined array key "b" in /in/p0fnK on line 13 NULL NULL Define a new variable: $n=1 Warning: Undefined array key "b" in /in/p0fnK on line 28 Warning: Undefined array key "b" in /in/p0fnK on line 13 NULL NULL
Output for 5.3.18 - 5.3.29, 5.4.8 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
ArrayObject dump: object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(2) { [0]=> array(0) { } [""]=> array(1) { ["bar"]=> string(3) "foo" } } } Non-existing array elements (current scope, function scope) Notice: Undefined index: b in /in/p0fnK on line 20 Notice: Undefined index: b in /in/p0fnK on line 13 NULL NULL Define a new variable: $s='hohohoooo' Notice: Undefined index: b in /in/p0fnK on line 24 Notice: Undefined index: b in /in/p0fnK on line 13 NULL NULL Define a new variable: $n=1 Notice: Undefined index: b in /in/p0fnK on line 28 Notice: Undefined index: b in /in/p0fnK on line 13 NULL NULL
Output for 7.3.32 - 7.3.33, 7.4.26
ArrayObject dump: object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(2) { [0]=> array(0) { } [""]=> array(1) { ["bar"]=> string(3) "foo" } } } Non-existing array elements (current scope, function scope) NULL NULL Define a new variable: $s='hohohoooo' NULL NULL Define a new variable: $n=1 NULL NULL
Output for 5.3.0 - 5.3.17, 5.4.0 - 5.4.7
Warning: Illegal offset type in /in/p0fnK on line 7 ArrayObject dump: object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(1) { [0]=> array(0) { } } } Non-existing array elements (current scope, function scope) Notice: Undefined index: b in /in/p0fnK on line 20 Notice: Undefined index: b in /in/p0fnK on line 13 array(1) { ["bar"]=> string(3) "foo" } array(1) { ["bar"]=> string(3) "foo" } Define a new variable: $s='hohohoooo' Notice: Undefined index: b in /in/p0fnK on line 24 Notice: Undefined index: b in /in/p0fnK on line 13 string(9) "hohohoooo" string(9) "hohohoooo" Define a new variable: $n=1 Notice: Undefined index: b in /in/p0fnK on line 28 Notice: Undefined index: b in /in/p0fnK on line 13 int(1) int(1)
Output for 5.2.0 - 5.2.17
Warning: Illegal offset type in /in/p0fnK on line 7 ArrayObject dump: object(ArrayObject)#1 (1) { [0]=> array(0) { } } Non-existing array elements (current scope, function scope) Notice: Undefined index: b in /in/p0fnK on line 20 Notice: Undefined index: b in /in/p0fnK on line 13 array(1) { ["bar"]=> string(3) "foo" } array(1) { ["bar"]=> string(3) "foo" } Define a new variable: $s='hohohoooo' Notice: Undefined index: b in /in/p0fnK on line 24 Notice: Undefined index: b in /in/p0fnK on line 13 array(1) { ["bar"]=> string(3) "foo" } array(1) { ["bar"]=> string(3) "foo" } Define a new variable: $n=1 Notice: Undefined index: b in /in/p0fnK on line 28 Notice: Undefined index: b in /in/p0fnK on line 13 array(1) { ["bar"]=> string(3) "foo" } array(1) { ["bar"]=> string(3) "foo" }
Output for 5.1.0 - 5.1.6
Warning: Illegal offset type in /in/p0fnK on line 7 Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in /in/p0fnK on line 7
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Illegal offset type in /in/p0fnK on line 6 Warning: Illegal offset type in /in/p0fnK on line 7 Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in /in/p0fnK on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: arrayobject in /in/p0fnK on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: arrayobject in /in/p0fnK on line 5

preferences:
326.09 ms | 401 KiB | 460 Q