3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function remove_recursion($o){ static $replace; if(!isset($replace)) $replace = create_function('$m','$r="\x00{$m[1]}ecursion_";return \'s:\'.strlen($r.$m[2]).\':"\'.$r.$m[2].\'";\';') ; if(is_array($o) || is_object($o)){ $re = '#(r|R):([0-9]+);#'; $serialize = serialize($o); if(preg_match($re, $serialize)){ $last = $pos = 0; while(false !== ($pos = strpos($serialize, 's:', $pos))){ $chunk = substr($serialize, $last, $pos - $last); if(preg_match($re, $chunk)){ $length = strlen($chunk); $chunk = preg_replace_callback($re, $replace, $chunk); $serialize = substr($serialize, 0, $last).$chunk.substr($serialize, $last + ($pos - $last)); $pos += strlen($chunk) - $length; } $pos += 2; $last = strpos($serialize, ':', $pos); $length = substr($serialize, $pos, $last- $pos); $last += 4 + $length; $pos = $last; } $serialize = substr($serialize, 0, $last).preg_replace_callback($re, $replace, substr($serialize, $last)); $o = unserialize($serialize); } } return $o; } $o = new stdClass; $o->n = function($a) { return $a; }; $o->r = &$o; echo serialize($o), ' ', serialize( remove_recursion($o) ) ;
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in /in/lOjLg:37 Stack trace: #0 /in/lOjLg(37): serialize(Object(stdClass)) #1 {main} thrown in /in/lOjLg on line 37
Process exited with code 255.
Output for hhvm-3.12.0 - 3.13.2
Warning: Attempted to serialize unserializable builtin class Closure$remove_recursion;1495396935$1180c957040f1348cddfa6ec6e6eacd5$ in /in/lOjLg on line 37 O:8:"stdClass":2:{s:1:"n";N;s:1:"r";r:1;} Warning: Attempted to serialize unserializable builtin class Closure$remove_recursion;1495396935$1180c957040f1348cddfa6ec6e6eacd5$ in /in/lOjLg on line 9 O:8:"stdClass":2:{s:1:"n";N;s:1:"r";s:12:"recursion_1";}
Output for hhvm-3.10.0
Warning: Attempted to serialize unserializable builtin class Closure$remove_recursion;1495396935$bb1839c80ba69a7961c61ed6f8a8f9$ in /in/lOjLg on line 37 O:8:"stdClass":2:{s:1:"n";N;s:1:"r";r:1;} Warning: Attempted to serialize unserializable builtin class Closure$remove_recursion;1495396935$bb1839c80ba69a7961c61ed6f8a8f9$ in /in/lOjLg on line 9 O:8:"stdClass":2:{s:1:"n";N;s:1:"r";s:12:"recursion_1";}
Output for 5.3.0 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /in/lOjLg:37 Stack trace: #0 /in/lOjLg(37): serialize(Object(stdClass)) #1 {main} thrown in /in/lOjLg on line 37
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/lOjLg on line 34
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/lOjLg on line 34
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/lOjLg on line 34
Process exited with code 255.