3v4l.org

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

End of function test

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

End of function %00%7Bclosure%7D%2Fin%2FY6bAc%3A23%240

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

End of function f

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.02 ms | 1407 KiB | 17 Q