3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_to_anon_object($arr): object { $obj = new class {}; foreach ( $arr as $key => $value ) { $obj->{$key} = $value; } return $obj; } class EmptyClass {} function array_to_normal_object($arr, $className): object { $obj = new class {}; foreach ( $arr as $key => $value ) { $obj->{$key} = $value; } return $obj; } var_dump( json_encode([1,2,3]) ); var_dump( json_encode((object)[1,2,3]) ); var_dump( json_encode(array_to_anon_object([1,2,3])) ); var_dump( json_encode(array_to_normal_object([1,2,3], EmptyClass::class)) );
Output for git.master, git.master_jit, rfc.property-hooks
string(7) "[1,2,3]" string(19) "{"0":1,"1":2,"2":3}" Deprecated: Creation of dynamic property class@anonymous::$0 is deprecated in /in/kbVnu on line 6 Deprecated: Creation of dynamic property class@anonymous::$1 is deprecated in /in/kbVnu on line 6 Deprecated: Creation of dynamic property class@anonymous::$2 is deprecated in /in/kbVnu on line 6 string(19) "{"0":1,"1":2,"2":3}" Deprecated: Creation of dynamic property class@anonymous::$0 is deprecated in /in/kbVnu on line 16 Deprecated: Creation of dynamic property class@anonymous::$1 is deprecated in /in/kbVnu on line 16 Deprecated: Creation of dynamic property class@anonymous::$2 is deprecated in /in/kbVnu on line 16 string(19) "{"0":1,"1":2,"2":3}"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
61.85 ms | 402 KiB | 8 Q