3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array('1' => 'One',); $a['2'] = 'Two'; $o = (object)$a; $o->{3} = 'Three'; $o->{'4'} = 'Four'; foreach( $o as $k => $v ){ var_dump( $k ); } echo "\n"; var_dump( $o ); echo "\n\n"; $a = (array)$o; foreach( $a as $k => $v ){ var_dump( $k ); } echo "\n"; var_dump( $a ); echo "\n\n"; $a = (array)json_decode(json_encode($a)); foreach( $a as $k => $v ){ var_dump( $k ); } echo "\n"; var_dump( $a );
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.26, 8.1.0 - 8.1.13
string(1) "1" string(1) "2" string(1) "3" string(1) "4" object(stdClass)#1 (4) { ["1"]=> string(3) "One" ["2"]=> string(3) "Two" ["3"]=> string(5) "Three" ["4"]=> string(4) "Four" } int(1) int(2) int(3) int(4) array(4) { [1]=> string(3) "One" [2]=> string(3) "Two" [3]=> string(5) "Three" [4]=> string(4) "Four" } int(1) int(2) int(3) int(4) array(4) { [1]=> string(3) "One" [2]=> string(3) "Two" [3]=> string(5) "Three" [4]=> string(4) "Four" }
Output for 5.2.1 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 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
int(1) int(2) string(1) "3" string(1) "4" object(stdClass)#1 (4) { [1]=> string(3) "One" [2]=> string(3) "Two" ["3"]=> string(5) "Three" ["4"]=> string(4) "Four" } int(1) int(2) string(1) "3" string(1) "4" array(4) { [1]=> string(3) "One" [2]=> string(3) "Two" ["3"]=> string(5) "Three" ["4"]=> string(4) "Four" } string(1) "1" string(1) "2" string(1) "3" string(1) "4" array(4) { ["1"]=> string(3) "One" ["2"]=> string(3) "Two" ["3"]=> string(5) "Three" ["4"]=> string(4) "Four" }
Output for 4.3.0 - 4.3.2, 5.2.0

Process exited with code 139.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
string(1) "3" string(1) "4" object(stdClass)#1 (4) { [1]=> string(3) "One" [2]=> string(3) "Two" ["3"]=> string(5) "Three" ["4"]=> string(4) "Four" } int(1) int(2) string(1) "3" string(1) "4" array(4) { [1]=> string(3) "One" [2]=> string(3) "Two" ["3"]=> string(5) "Three" ["4"]=> string(4) "Four" } Fatal error: Call to undefined function json_decode() in /in/cJPlX on line 18
Process exited with code 255.
Output for 4.3.3 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Property name must be a string in /in/cJPlX on line 5
Process exited with code 255.

preferences:
90.79 ms | 415 KiB | 5 Q