3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
The state is: invalid!
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/JsiFW on line 27
Process exited with code 255.