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();
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property class@anonymous::$s is deprecated in /in/m479s on line 15 array(2) { [0]=> array(4) { ["file"]=> string(9) "/in/m479s" ["line"]=> int(18) ["function"]=> string(9) "mimicking" ["args"]=> array(2) { [0]=> object(A)#1 (1) { ["stuff":protected]=> int(10) } [1]=> object(Closure)#3 (1) { ["this"]=> object(class@anonymous)#2 (1) { ["s"]=> object(A)#1 (1) { ["stuff":protected]=> int(10) } } } } } [1]=> array(7) { ["file"]=> string(9) "/in/m479s" ["line"]=> int(27) ["function"]=> string(3) "asd" ["class"]=> string(30) "class@anonymous/in/m479s:13$0" ["object"]=> object(class@anonymous)#2 (1) { ["s"]=> object(A)#1 (1) { ["stuff":protected]=> int(10) } } ["type"]=> string(2) "->" ["args"]=> array(0) { } } } Fatal error: Uncaught Error: Cannot access protected property A::$stuff in /in/m479s:19 Stack trace: #0 /in/m479s(6): class@anonymous->{closure}() #1 /in/m479s(7): A::{closure}() #2 /in/m479s(18): mimicking(Object(A), Object(Closure)) #3 /in/m479s(27): class@anonymous->asd() #4 {main} thrown in /in/m479s on line 19
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.97 ms | 403 KiB | 8 Q