3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class foo { private $proxy; public function __construct(self $proxy = null) { $this->proxy = $proxy ?: $this; } public function getFoo() { extract(['this' => $this->proxy]); echo get_class($this); $f = function () { return $this->foo; }; return $f(); } } class fooProxy extends foo { private $foo; public function __construct($foo) { $this->foo = $foo; parent::__construct($this); } public function __set($name, $value) { echo __FUNCTION__, "\n"; $this->$name = $value; } public function __get($name) { echo __FUNCTION__, "\n"; return $this->$name; } } $p = new foo(new fooProxy(123)); echo $p->getFoo(); echo "\n";
based on WBlGY
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught Error: Cannot re-assign $this in /in/5JavK:14 Stack trace: #0 /in/5JavK(14): extract(Array) #1 /in/5JavK(49): foo->getFoo() #2 {main} thrown in /in/5JavK on line 14
Process exited with code 255.
Output for 5.4.1 - 7.0.20
foo Notice: Undefined property: foo::$foo in /in/5JavK on line 17
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/5JavK on line 14
Process exited with code 255.