3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Example { private $label; public function __construct($label) { $this->label = $label; } public function __sleep() { echo "Attempt to serialize object with label $this->label\n"; return array('label'); } public function __destruct() { echo "Refcount reached zero for object with label $this->label\n"; } public function throwSomething($unused_parameter) { throw new Exception; } } echo "-- No object in stack trace --\n"; $target = new Example('Target of method call'); try { $target->throwSomething('irrelevant data'); } catch ( Exception $e ) { // Serialize exception, doesn't touch object var_dump(serialize($e)); // Destroy $target, as there are no other references to it unset($target); } echo "-- No object as argument captured in stack trace --\n"; $target = new Example('Target of method call'); $parameter = new Example('Parameter passed but never actually used'); try { $target->throwSomething($parameter); } catch ( Exception $e ) { // Serialize exception, will attempt to serialize $parameter var_dump(serialize($e)); // Destroy $target, as there are no other references to it unset($target); // Attempt to do the same for $parameter, Exception holds a reference unset($parameter); } echo "-- PHP process cleanup begins here --\n";
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
-- No object in stack trace -- string(383) "O:9:"Exception":7:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}s:19:"Exceptionprevious";N;}" Refcount reached zero for object with label Target of method call -- No object as argument captured in stack trace -- Attempt to serialize object with label Parameter passed but never actually used string(448) "O:9:"Exception":7:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:14:"Examplelabel";s:40:"Parameter passed but never actually used";}}}}s:19:"Exceptionprevious";N;}" Refcount reached zero for object with label Target of method call -- PHP process cleanup begins here -- Refcount reached zero for object with label Parameter passed but never actually used
Output for 5.0.2, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
-- No object in stack trace -- string(354) "O:9:"Exception":6:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}" Refcount reached zero for object with label Target of method call -- No object as argument captured in stack trace -- Attempt to serialize object with label Parameter passed but never actually used string(419) "O:9:"Exception":6:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:14:"Examplelabel";s:40:"Parameter passed but never actually used";}}}}}" Refcount reached zero for object with label Target of method call -- PHP process cleanup begins here -- Refcount reached zero for object with label Parameter passed but never actually used
Output for 5.0.5
-- No object in stack trace -- string(354) "O:9:"Exception":6:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}" Refcount reached zero for object with label Target of method call -- No object as argument captured in stack trace -- Attempt to serialize object with label Parameter passed but never actually used
Process exited with code 139.
Output for 5.0.3 - 5.0.4
-- No object in stack trace -- string(490) "O:9:"Exception":6:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:2:{i:0;a:5:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:16;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"::";}i:1;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}" Refcount reached zero for object with label Target of method call -- No object as argument captured in stack trace -- Attempt to serialize object with label Parameter passed but never actually used string(555) "O:9:"Exception":6:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:2:{i:0;a:5:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:16;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"::";}i:1;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:14:"Examplelabel";s:40:"Parameter passed but never actually used";}}}}}" Refcount reached zero for object with label Target of method call -- PHP process cleanup begins here -- Refcount reached zero for object with label Parameter passed but never actually used
Output for 5.0.0 - 5.0.1
-- No object in stack trace -- string(354) "O:9:"Exception":6:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:23;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;s:15:"irrelevant data";}}}}" Refcount reached zero for object with label Target of method call -- No object as argument captured in stack trace -- Attempt to serialize object with label Parameter passed but never actually used string(363) "O:9:"Exception":6:{s:10:"*message";s:0:"";s:17:"Exceptionstring";s:0:"";s:7:"*code";i:0;s:7:"*file";s:9:"/in/hOYb9";s:7:"*line";i:16;s:16:"Exceptiontrace";a:1:{i:0;a:6:{s:4:"file";s:9:"/in/hOYb9";s:4:"line";i:36;s:8:"function";s:14:"throwSomething";s:5:"class";s:7:"Example";s:4:"type";s:2:"->";s:4:"args";a:1:{i:0;O:7:"Example":1:{s:5:"label";N;}}}}}" Refcount reached zero for object with label Target of method call -- PHP process cleanup begins here -- Refcount reached zero for object with label Parameter passed but never actually used
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/hOYb9 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/hOYb9 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/hOYb9 on line 4
Process exited with code 255.

preferences:
152.1 ms | 421 KiB | 5 Q