3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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; }
based on CclM7
Output for 5.3.0 - 7.2.0
{"_PHP_ASSOC":{"hoge":{}}} Notice: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Notice: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Array ( [hoge] => stdClass Object ( ) )
Output for 5.2.6 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vZctd on line 2 {"_PHP_ASSOC":{"hoge":{}}} Notice: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Notice: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Array ( [hoge] => stdClass Object ( ) )
Output for 5.2.0 - 5.2.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vZctd on line 2 {"_PHP_ASSOC":{"hoge":{}}} Notice: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Notice: Undefined property: stdClass::$_PHP_ASSOC in /in/vZctd on line 29 Array ( [hoge] => stdClass Object ( ) )
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vZctd on line 2 Fatal error: Call to undefined function json_encode() in /in/vZctd on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vZctd on line 2 Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/vZctd on line 21
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vZctd on line 2 Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/vZctd on line 21
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vZctd on line 2 Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/vZctd on line 21
Process exited with code 255.