3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php foreach (array(null, false, true, '', 'asdf', 0, 0.0) as $foo) { $foo["bar"] = "baz"; var_dump($foo); }
based on kNans
Output for 7.1.0 - 7.3.0beta1
array(1) { ["bar"]=> string(3) "baz" } array(1) { ["bar"]=> string(3) "baz" } Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 bool(true) Warning: Illegal string offset 'bar' in /in/EYaRC on line 4 string(1) "b" Warning: Illegal string offset 'bar' in /in/EYaRC on line 4 string(4) "bsdf" Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 int(0) Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 float(0)
Output for 5.4.0 - 7.0.20
array(1) { ["bar"]=> string(3) "baz" } array(1) { ["bar"]=> string(3) "baz" } Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 bool(true) array(1) { ["bar"]=> string(3) "baz" } Warning: Illegal string offset 'bar' in /in/EYaRC on line 4 string(4) "bsdf" Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 int(0) Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 float(0)
Output for 4.3.0 - 5.3.29
array(1) { ["bar"]=> string(3) "baz" } array(1) { ["bar"]=> string(3) "baz" } Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 bool(true) array(1) { ["bar"]=> string(3) "baz" } string(4) "bsdf" Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 int(0) Warning: Cannot use a scalar value as an array in /in/EYaRC on line 4 float(0)