3v4l.org

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

End of function test

Function %00%7Bclosure%7D%2Fin%2FFSIjE%3A13%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FSIjE
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%2FFSIjE%3A13%240

Class C:
Function f:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FSIjE
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%2FFSIjE%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:
159.17 ms | 948 KiB | 18 Q