3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Observer { protected function callme() { } } class MyParent extends Observer { function createChild() { $this->callme(); // this is OK return new MyChild (function() { $this->callme(); }); } } class MyChild { private $gatewayFunction; public function __constructor (Closure $gatewayFunction) { $this->gatewayFunction = $gatewayFunction; } public function __destroy() { $this->gatewayFunction->__invoke(); } } $p = new MyParent(); $c = $p->createChild(); var_dump($c); $c->__destroy();

preferences:
36.08 ms | 402 KiB | 5 Q