3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar { private $state = "valid"; public function getState(){ return $this->state; } public function changeState($inject){ $this->state = "invalid"; // State is temporarily invalid. It will be // valid again before the method returns. // This is ok, right? $inject->qux(); // State is valid again, the method returns. $this->state = "valid"; } } $bar = new Bar(); $bar->changeState(new class($bar){ function __construct(Bar $bar){ $this->bar = $bar; } function qux(){ echo "The state is: " . $this->bar->getState() . "!"; } });
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property class@anonymous::$bar is deprecated in /in/JsiFW on line 30 The state is: invalid!

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:
58.98 ms | 401 KiB | 8 Q