3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formaldehyde_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 = $o; $o->r = &$o; echo serialize($o), ' ', serialize( remove_recursion($o) ) ;
Output for 7.0.20, 7.1.5 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
O:8:"stdClass":2:{s:1:"n";r:1;s:1:"r";R:1;} Fatal error: Uncaught Error: Call to undefined function remove_recursion() in /in/Sfc4e:40 Stack trace: #0 {main} thrown in /in/Sfc4e on line 40
Process exited with code 255.
Output for 7.0.0 - 7.0.14, 7.1.0
O:8:"stdClass":2:{s:1:"n";r:1;s:1:"r";R:1;} Fatal error: Uncaught Error: Call to undefined function remove_recursion() in /in/Sfc4e:39 Stack trace: #0 {main} thrown in /in/Sfc4e on line 39
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
O:8:"stdClass":2:{s:1:"n";r:1;s:1:"r";R:1;} Fatal error: Call to undefined function remove_recursion() in /in/Sfc4e on line 40
Process exited with code 255.
Output for 5.0.0 - 5.0.5
O:8:"stdClass":2:{s:1:"n";r:1;s:1:"r";r:1;} Fatal error: Call to undefined function remove_recursion() in /in/Sfc4e on line 40
Process exited with code 255.
Output for 4.4.5 - 4.4.9
O:8:"stdClass":2:{s:1:"n";O:8:"stdClass":0:{}s:1:"r";O:8:"stdClass":2:{s:1:"n";r:2;s:1:"r";R:3;}} Fatal error: Call to undefined function: remove_recursion() in /in/Sfc4e on line 40
Process exited with code 255.
Output for 4.3.10 - 4.3.11, 4.4.0 - 4.4.4
O:8:"stdClass":2:{s:1:"n";O:8:"stdClass":0:{}s:1:"r";O:8:"stdClass":2:{s:1:"n";r:2;s:1:"r";R:3;}} Fatal error: Call to undefined function: remove_recursion() in /in/Sfc4e on line 40
Process exited with code 255.
Output for 4.3.2 - 4.3.9
O:8:"stdClass":2:{s:1:"n";O:8:"stdClass":0:{}s:1:"r";O:8:"stdClass":2:{s:1:"n";O:8:"stdClass":0:{}s:1:"r";R:3;}} Fatal error: Call to undefined function: remove_recursion() in /in/Sfc4e on line 40
Process exited with code 255.
Output for 4.3.0 - 4.3.1
O:8:"stdClass":2:{s:1:"n";O:8:"stdClass":0:{}s:1:"r";O:8:"stdClass":2:{s:1:"n";O:8:"stdClass":0:{}s:1:"r";R:3;}} Fatal error: Call to undefined function: remove_recursion() in /in/Sfc4e on line 40

preferences:
220.25 ms | 402 KiB | 316 Q