3v4l.org

run code in 300+ PHP versions simultaneously
<?php $r = array('hoge'=> new \stdClass()); $j = json_serialize($r); echo $j . "\n"; print_r(json_unserialize($j)); echo "\n"; function json_serialize($any) { return json_encode(json_wrap($any)); } function json_unserialize($str) { return json_unwrap(json_decode($str)); } function json_wrap($any, $skipAssoc = false) { if (!$skipAssoc && is_array($any) && is_string(key($any))) { return (object)array("_PHP_ASSOC" => json_wrap($any,true)); } if (is_array($any) || is_object($any)) { foreach ($any as &$v) { $v = json_wrap($v); } } return $any; } function json_unwrap($any, $skipAssoc = false) { if (!$skipAssoc && is_object($any) && is_object($any->_PHP_ASSOC) && count((array)$any) == 1) { return (array)json_unwrap($any->_PHP_ASSOC); } if (is_array($any) || is_object($any)) { foreach ($any as &$v) { $v = json_unwrap($v); } } return $any; }
Output for git.master, git.master_jit, rfc.property-hooks
{"_PHP_ASSOC":{"hoge":{}}} Warning: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Warning: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Array ( [hoge] => stdClass Object ( ) )

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:
49.42 ms | 402 KiB | 8 Q