3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mimicking($obj, $exec){ var_dump(debug_backtrace()); return (function() use($exec){ return $exec(); })->bindTo(null, $obj)(); } class A{ protected $stuff = 10; function test(){ return new class($this){ function __construct(A $s){ $this->s = $s; } function asd(){ return mimicking($this->s, function(){ return $this->s->stuff; }); } }; } } $x = new A; echo $x->test()->asd();

preferences:
50.8 ms | 402 KiB | 5 Q