3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fn = function () { return get_called_class(); }; var_dump((new ReflectionFunction($fn))->getClosureScopeClass()); class C { private static $test = 'In class C'; public function __construct() { $fn = function () { return get_called_class(); }; $res = (new ReflectionFunction($fn))->getClosureScopeClass(); var_dump(get_class($res)); var_dump($res->getName()); } public static function s_fn() { $fn = function () { var_dump(static::$test); return get_called_class(); }; $res = (new ReflectionFunction($fn))->getClosureScopeClass(); var_dump(get_class($res)); var_dump($res->getName()); var_dump(static::$test); return $fn; } } class D extends C { private static $test = 'In class D'; public function __construct() { static::s_fn(); } public static function test() { return static::s_fn(); } } $c = new C; C::s_fn(); $d = new D; $func = D::test(); var_dump($func());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  (null)
number of ops:  27
compiled vars:  !0 = $fn, !1 = $c, !2 = $d, !3 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5rOPI%3A2%240'
          1        ASSIGN                                                   !0, ~4
    3     2        INIT_FCALL                                               'var_dump'
          3        NEW                                              $6      'ReflectionFunction'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        INIT_METHOD_CALL                                         $6, 'getClosureScopeClass'
          7        DO_FCALL                                      0  $8      
          8        SEND_VAR                                                 $8
          9        DO_ICALL                                                 
   34    10        NEW                                              $10     'C'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $10
   35    13        INIT_STATIC_METHOD_CALL                                  'C', 's_fn'
         14        DO_FCALL                                      0          
   36    15        NEW                                              $14     'D'
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !2, $14
   38    18        INIT_STATIC_METHOD_CALL                                  'D', 'test'
         19        DO_FCALL                                      0  $17     
         20        ASSIGN                                                   !3, $17
   39    21        INIT_FCALL                                               'var_dump'
         22        INIT_DYNAMIC_CALL                                        !3
         23        DO_FCALL                                      0  $19     
         24        SEND_VAR                                                 $19
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F5rOPI%3A2%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  {closure}
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   GET_CALLED_CLASS                                 ~0      
          1      > RETURN                                                   ~0
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F5rOPI%3A2%240

Function %00%7Bclosure%7D%2Fin%2F5rOPI%3A8%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  {closure}
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   GET_CALLED_CLASS                                 ~0      
          1      > RETURN                                                   ~0
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F5rOPI%3A8%241

Function %00%7Bclosure%7D%2Fin%2F5rOPI%3A16%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  {closure}
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'var_dump'
          1        FETCH_STATIC_PROP_R          global lock         ~0      'test'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                                 
          4        GET_CALLED_CLASS                                 ~2      
          5      > RETURN                                                   ~2
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F5rOPI%3A16%242

Class C:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  __construct
number of ops:  18
compiled vars:  !0 = $fn, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5rOPI%3A8%241'
          1        ASSIGN                                                   !0, ~2
    9     2        NEW                                              $4      'ReflectionFunction'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $4, 'getClosureScopeClass'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   11     8        INIT_FCALL                                               'var_dump'
          9        GET_CLASS                                        ~8      !1
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                                 
   12    12        INIT_FCALL                                               'var_dump'
         13        INIT_METHOD_CALL                                         !1, 'getName'
         14        DO_FCALL                                      0  $10     
         15        SEND_VAR                                                 $10
         16        DO_ICALL                                                 
   13    17      > RETURN                                                   null

End of function __construct

Function s_fn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  s_fn
number of ops:  23
compiled vars:  !0 = $fn, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5rOPI%3A16%242'
          1        ASSIGN                                                   !0, ~2
   17     2        NEW                                              $4      'ReflectionFunction'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $4, 'getClosureScopeClass'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   19     8        INIT_FCALL                                               'var_dump'
          9        GET_CLASS                                        ~8      !1
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                                 
   20    12        INIT_FCALL                                               'var_dump'
         13        INIT_METHOD_CALL                                         !1, 'getName'
         14        DO_FCALL                                      0  $10     
         15        SEND_VAR                                                 $10
         16        DO_ICALL                                                 
   21    17        INIT_FCALL                                               'var_dump'
         18        FETCH_STATIC_PROP_R          unknown             ~12     'test'
         19        SEND_VAL                                                 ~12
         20        DO_ICALL                                                 
   22    21      > RETURN                                                   !0
   23    22*     > RETURN                                                   null

End of function s_fn

End of class C.

Class D:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_STATIC_METHOD_CALL                                  's_fn'
          1        DO_FCALL                                      0          
   30     2      > RETURN                                                   null

End of function __construct

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  test
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_STATIC_METHOD_CALL                                  's_fn'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
          3*     > RETURN                                                   null

End of function test

Function s_fn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5rOPI
function name:  s_fn
number of ops:  23
compiled vars:  !0 = $fn, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5rOPI%3A16%242'
          1        ASSIGN                                                   !0, ~2
   17     2        NEW                                              $4      'ReflectionFunction'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $4, 'getClosureScopeClass'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   19     8        INIT_FCALL                                               'var_dump'
          9        GET_CLASS                                        ~8      !1
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                                 
   20    12        INIT_FCALL                                               'var_dump'
         13        INIT_METHOD_CALL                                         !1, 'getName'
         14        DO_FCALL                                      0  $10     
         15        SEND_VAR                                                 $10
         16        DO_ICALL                                                 
   21    17        INIT_FCALL                                               'var_dump'
         18        FETCH_STATIC_PROP_R          unknown             ~12     'test'
         19        SEND_VAL                                                 ~12
         20        DO_ICALL                                                 
   22    21      > RETURN                                                   !0
   23    22*     > RETURN                                                   null

End of function s_fn

End of class D.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.95 ms | 1408 KiB | 15 Q