3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foobar { public $baz; function __destruct() { # Don't do either of these, if $baz also has a __destruct()! $this->baz = null; unset($this->baz); # Instead, don't clear it at all, or do this: $this->baz->__destruct(); } } # Some function that throws an exception function fail($foobar) { throw new Exception("Exception A!"); } $foobar = new Foobar(); $foobar->baz = new Foobar(); try { fail($foobar); // Send foobar to func that throws an Exception } catch( Exception $e ) { print $e->getMessage(); // Exception A will be caught and printed, as expected. } $foobar = null; // clearing foobar, and its property $baz try { print 'Exception B:';// this will be printed // output stops here. throw new Exception("Exception B!"); } catch( Exception $e ) { print $e->getMessage(); // doesn't happen } print 'End'; // this won't be printed ?>
Output for git.master, git.master_jit, rfc.property-hooks
Exception A!Exception B: Warning: Undefined property: Foobar::$baz in /in/WpIMP on line 10 Fatal error: Uncaught Error: Call to a member function __destruct() on null in /in/WpIMP:10 Stack trace: #0 /in/WpIMP(6): Foobar->__destruct() #1 /in/WpIMP(34): Foobar->__destruct() #2 {main} thrown in /in/WpIMP on line 10
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.39 ms | 401 KiB | 8 Q