3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = (object) [ 'id' => 123, 'firstname' => 'james', 'lastname' => 'test', ]; $remapped_obj = new stdClass; foreach ($obj as $key => $value) { $remapped_obj->{$key$key} = $value; } $obj = $remapped_obj; var_dump($obj);
Output for 8.0.0 - 8.0.8
Parse error: syntax error, unexpected variable "$key" in /in/l7s0X on line 11
Process exited with code 255.
Output for 7.3.0 - 7.3.29, 7.4.0 - 7.4.21
Parse error: syntax error, unexpected '$key' (T_VARIABLE) in /in/l7s0X on line 11
Process exited with code 255.

preferences:
183.04 ms | 457 KiB | 5 Q