3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fn = function () { return get_called_class(); }; var_dump((new ReflectionFunction($fn))->getClosureScopeClass()); 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 () { return get_called_class(); }; $res = (new ReflectionFunction($fn))->getClosureScopeClass(); var_dump(get_class($res)); var_dump($res->getName()); } } class D extends C { public function __construct() { static::s_fn(); } } $c = new C; C::s_fn(); $d = new D;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k6m0E
function name:  (null)
number of ops:  19
compiled vars:  !0 = $fn, !1 = $c, !2 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fk6m0E%3A3%240'
          1        ASSIGN                                                   !0, ~3
    4     2        INIT_FCALL                                               'var_dump'
          3        NEW                                              $5      'ReflectionFunction'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        INIT_METHOD_CALL                                         $5, 'getClosureScopeClass'
          7        DO_FCALL                                      0  $7      
          8        SEND_VAR                                                 $7
          9        DO_ICALL                                                 
   30    10        NEW                                              $9      'C'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $9
   31    13        INIT_STATIC_METHOD_CALL                                  'C', 's_fn'
         14        DO_FCALL                                      0          
   32    15        NEW                                              $13     'D'
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !2, $13
         18      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2Fk6m0E%3A3%240

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

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

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

Class C:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k6m0E
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%2Fk6m0E%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/k6m0E
function name:  s_fn
number of ops:  18
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%2Fk6m0E%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      > 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/k6m0E
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_STATIC_METHOD_CALL                                  's_fn'
          1        DO_FCALL                                      0          
   27     2      > 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/k6m0E
function name:  s_fn
number of ops:  18
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%2Fk6m0E%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      > RETURN                                                   null

End of function s_fn

End of class D.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.83 ms | 1404 KiB | 15 Q