3v4l.org

run code in 300+ PHP versions simultaneously
<?php $emptyobject = new stdClass(); foreach ($emptyobject as $key => $value) { echo "Empty object: {$key} = {$value}\n"; } $filledobject = new stdClass(); $filledobject->foo = "foo"; $filledobject->bar = "bar"; foreach ($filledobject as $key => $value) { echo "Filled object: {$key} = {$value}\n"; } $string = "abc"; foreach ($string as $key => $value) { echo "String: {$key} = {$value}\n"; } $number = 123; foreach ($number as $key => $value) { echo "Number: {$key} = {$value}\n"; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Filled object: foo = foo Filled object: bar = bar Warning: foreach() argument must be of type array|object, string given in /in/CCrFo on line 16 Warning: foreach() argument must be of type array|object, int given in /in/CCrFo on line 21
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Filled object: foo = foo Filled object: bar = bar Warning: Invalid argument supplied for foreach() in /in/CCrFo on line 16 Warning: Invalid argument supplied for foreach() in /in/CCrFo on line 21

preferences:
146.03 ms | 409 KiB | 5 Q