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";

preferences:
24.92 ms | 405 KiB | 5 Q