3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test(ReflectionFunctionAbstract $r) { var_dump($r->isClosure()); $dc = $r->getDeclaringClass(); var_dump($dc ? $dc->getName() : 'no declaring class'); $csc = $r->getClosureScopeClass(); var_dump($csc ? $csc->getName() : 'no closure scope class'); echo "\n\n"; } class C { function f() { return function($p) {}; } } $c = new C; $cl = $c->f(); // instantiate ReflectionFunction directly on closure $rf = new ReflectionFunction($cl); test($rf); // get ReflectionFunction via one of the initial ReflectionFunction's ReflectionParameter objects $rps = $rf->getParameters(); $rp = $rps[0]; test($rp->getDeclaringFunction());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MMvgW
function name:  (null)
number of ops:  24
compiled vars:  !0 = $c, !1 = $cl, !2 = $rf, !3 = $rps, !4 = $rp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   NEW                                              $5      'C'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $5
          3        INIT_METHOD_CALL                                         !0, 'f'
          4        DO_FCALL                                      0  $8      
          5        ASSIGN                                                   !1, $8
   19     6        NEW                                              $10     'ReflectionFunction'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $10
   20    10        INIT_FCALL                                               'test'
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0          
   23    13        INIT_METHOD_CALL                                         !2, 'getParameters'
         14        DO_FCALL                                      0  $14     
         15        ASSIGN                                                   !3, $14
   24    16        FETCH_DIM_R                                      ~16     !3, 0
         17        ASSIGN                                                   !4, ~16
   25    18        INIT_FCALL                                               'test'
         19        INIT_METHOD_CALL                                         !4, 'getDeclaringFunction'
         20        DO_FCALL                                      0  $18     
         21        SEND_VAR                                                 $18
         22        DO_FCALL                                      0          
         23      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
Branch analysis from position: 27
filename:       /in/MMvgW
function name:  test
number of ops:  32
compiled vars:  !0 = $r, !1 = $dc, !2 = $csc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'var_dump'
          2        INIT_METHOD_CALL                                         !0, 'isClosure'
          3        DO_FCALL                                      0  $3      
          4        SEND_VAR                                                 $3
          5        DO_ICALL                                                 
    4     6        INIT_METHOD_CALL                                         !0, 'getDeclaringClass'
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !1, $5
    5     9        INIT_FCALL                                               'var_dump'
         10      > JMPZ                                                     !1, ->15
         11    >   INIT_METHOD_CALL                                         !1, 'getName'
         12        DO_FCALL                                      0  $7      
         13        QM_ASSIGN                                        ~8      $7
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~8      'no+declaring+class'
         16    >   SEND_VAL                                                 ~8
         17        DO_ICALL                                                 
    6    18        INIT_METHOD_CALL                                         !0, 'getClosureScopeClass'
         19        DO_FCALL                                      0  $10     
         20        ASSIGN                                                   !2, $10
    7    21        INIT_FCALL                                               'var_dump'
         22      > JMPZ                                                     !2, ->27
         23    >   INIT_METHOD_CALL                                         !2, 'getName'
         24        DO_FCALL                                      0  $12     
         25        QM_ASSIGN                                        ~13     $12
         26      > JMP                                                      ->28
         27    >   QM_ASSIGN                                        ~13     'no+closure+scope+class'
         28    >   SEND_VAL                                                 ~13
         29        DO_ICALL                                                 
    8    30        ECHO                                                     '%0A%0A'
    9    31      > RETURN                                                   null

End of function test

Function %00%7Bclosure%7D%2Fin%2FMMvgW%3A13%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MMvgW
function name:  {closure}
number of ops:  2
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FMMvgW%3A13%240

Class C:
Function f:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MMvgW
function name:  f
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FMMvgW%3A13%240'
          1      > RETURN                                                   ~0
   14     2*     > RETURN                                                   null

End of function f

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.66 ms | 1403 KiB | 17 Q