3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mimicking($obj, Closure $exec){ $thisVal = (new ReflectionFunction($exec))->getClosureThis(); return $exec->bindTo($thisVal, $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();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSKjG
function name:  (null)
number of ops:  9
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   NEW                                              $1      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   25     3        INIT_METHOD_CALL                                         !0, 'test'
          4        DO_FCALL                                      0  $4      
          5        INIT_METHOD_CALL                                         $4, 'asd'
          6        DO_FCALL                                      0  $5      
          7        ECHO                                                     $5
          8      > RETURN                                                   1

Function mimicking:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSKjG
function name:  mimicking
number of ops:  16
compiled vars:  !0 = $obj, !1 = $exec, !2 = $thisVal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        NEW                                              $3      'ReflectionFunction'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $3, 'getClosureThis'
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !2, $5
    5     8        INIT_METHOD_CALL                                         !1, 'bindTo'
          9        SEND_VAR_EX                                              !2
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $7      
         12        INIT_DYNAMIC_CALL                                        $7
         13        DO_FCALL                                      0  $8      
         14      > RETURN                                                   $8
    6    15*     > RETURN                                                   null

End of function mimicking

Function %00%7Bclosure%7D%2Fin%2FhSKjG%3A16%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSKjG
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_THIS                                       $0      
          1        FETCH_OBJ_R                                      ~1      $0, 's'
          2        FETCH_OBJ_R                                      ~2      ~1, 'stuff'
          3      > RETURN                                                   ~2
   18     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhSKjG%3A16%241

Class class@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSKjG
function name:  __construct
number of ops:  4
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               's'
          2        OP_DATA                                                  !0
   14     3      > RETURN                                                   null

End of function __construct

Function asd:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSKjG
function name:  asd
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'mimicking'
          1        FETCH_OBJ_R                                      ~0      's'
          2        SEND_VAL                                                 ~0
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhSKjG%3A16%241'
   18     4        SEND_VAL                                                 ~1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   19     7*     > RETURN                                                   null

End of function asd

End of class class@anonymous.

Class A:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSKjG
function name:  test
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   DECLARE_ANON_CLASS                               <const ast>   
          1        NEW                                              $1      $0
          2        FETCH_THIS                                       $2      
          3        SEND_VAR_EX                                              $2
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $1
   21     6*     > RETURN                                                   null

End of function test

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.72 ms | 1403 KiB | 14 Q