<?php
class Foo
{
private $bar;
public function getBar()
{
return $this->bar;
}
}
class FooProxy extends Foo
{
public function getBar()
{
$this->init();
return parent::getBar();
}
private function init()
{
\Closure::bind(function (Foo $foo, $value) {
$foo->bar = $value;
}, null, \get_parent_class($this))($this, 'bar42');
}
}
$foo = new FooProxy();
var_dump($foo->getBar());
- Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.23, 8.3.0 - 8.3.11
- string(5) "bar42"
preferences:
67.65 ms | 407 KiB | 5 Q