3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test(ReflectionFunctionAbstract $r) { var_dump($r->isClosure()); if ($r instanceof ReflectionMethod) { $rc = $r->getDeclaringClass(); $dc = $rc ? $rc->getName() : 'no declaring class'; } else { $dc = 'not a ReflectionMethod'; } var_dump($dc ?: '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/VgIeT
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
-------------------------------------------------------------------------------------
   21     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
   24     6        NEW                                              $10     'ReflectionFunction'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $10
   25    10        INIT_FCALL                                               'test'
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0          
   28    13        INIT_METHOD_CALL                                         !2, 'getParameters'
         14        DO_FCALL                                      0  $14     
         15        ASSIGN                                                   !3, $14
   29    16        FETCH_DIM_R                                      ~16     !3, 0
         17        ASSIGN                                                   !4, ~16
   30    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 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
Branch analysis from position: 34
filename:       /in/VgIeT
function name:  test
number of ops:  39
compiled vars:  !0 = $r, !1 = $rc, !2 = $dc, !3 = $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  $4      
          4        SEND_VAR                                                 $4
          5        DO_ICALL                                                 
    4     6        INSTANCEOF                                               !0, 'ReflectionMethod'
          7      > JMPZ                                                     ~6, ->19
    5     8    >   INIT_METHOD_CALL                                         !0, 'getDeclaringClass'
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !1, $7
    6    11      > JMPZ                                                     !1, ->16
         12    >   INIT_METHOD_CALL                                         !1, 'getName'
         13        DO_FCALL                                      0  $9      
         14        QM_ASSIGN                                        ~10     $9
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~10     'no+declaring+class'
         17    >   ASSIGN                                                   !2, ~10
         18      > JMP                                                      ->20
    8    19    >   ASSIGN                                                   !2, 'not+a+ReflectionMethod'
   10    20    >   INIT_FCALL                                               'var_dump'
         21        JMP_SET                                          ~13     !2, ->23
         22        QM_ASSIGN                                        ~13     'no+declaring+class'
         23        SEND_VAL                                                 ~13
         24        DO_ICALL                                                 
   11    25        INIT_METHOD_CALL                                         !0, 'getClosureScopeClass'
         26        DO_FCALL                                      0  $15     
         27        ASSIGN                                                   !3, $15
   12    28        INIT_FCALL                                               'var_dump'
         29      > JMPZ                                                     !3, ->34
         30    >   INIT_METHOD_CALL                                         !3, 'getName'
         31        DO_FCALL                                      0  $17     
         32        QM_ASSIGN                                        ~18     $17
         33      > JMP                                                      ->35
         34    >   QM_ASSIGN                                        ~18     'no+closure+scope+class'
         35    >   SEND_VAL                                                 ~18
         36        DO_ICALL                                                 
   13    37        ECHO                                                     '%0A%0A'
   14    38      > RETURN                                                   null

End of function test

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

End of function %00%7Bclosure%7D%2Fin%2FVgIeT%3A18%240

Class C:
Function f:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VgIeT
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%2FVgIeT%3A18%240'
          1      > RETURN                                                   ~0
   19     2*     > RETURN                                                   null

End of function f

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.29 ms | 954 KiB | 18 Q