@ 2015-09-21T08:18:11Z <?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";
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.1.0 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 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 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.28 , 7.0.0 - 7.0.20 foo
Notice: Undefined property: foo::$foo in /in/5JavK on line 17
preferences:dark mode live preview
173.61 ms | 402 KiB | 226 Q