3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_calling_scope() { $trace = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT); array_shift($trace); // Remove current frame $frame = array_shift($trace); if ($frame === null) { return null; } $function = $frame['function']; if (!in_array($function, ['__get', '__set', '__isset', '__unset', '__call', '__callStatic'], true)) { return null; } $object = $frame['object'] ?? null; $property = $frame['args'][0]; foreach ($trace as $previousFrame) { $previousObject = $previousFrame['object'] ?? null; if ($previousFrame['function'] !== $function || $previousObject !== $object || $previousFrame['args'][0] !== $property) { return $previousObject !== null ? $previousObject::class : null; } } return null; } class Foo { public function __get($name) { var_dump(get_calling_scope()); return ''; } public function test() { $this->bar; } } class Bar extends Foo { public function __get($name) { parent::__get($name); return ''; } } $foo = new Foo(); $foo->bar; $foo->test(); $bar = new Bar(); $bar->test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6Ua8t
function name:  (null)
number of ops:  13
compiled vars:  !0 = $foo, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   NEW                                              $2      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   53     3        FETCH_OBJ_R                                      ~5      !0, 'bar'
          4        FREE                                                     ~5
   54     5        INIT_METHOD_CALL                                         !0, 'test'
          6        DO_FCALL                                      0          
   56     7        NEW                                              $7      'Bar'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $7
   57    10        INIT_METHOD_CALL                                         !1, 'test'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function get_calling_scope:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 53
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 53
Branch analysis from position: 29
2 jumps found. (Code = 47) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
2 jumps found. (Code = 47) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 52
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 43
Branch analysis from position: 38
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/6Ua8t
function name:  get_calling_scope
number of ops:  56
compiled vars:  !0 = $trace, !1 = $frame, !2 = $function, !3 = $object, !4 = $property, !5 = $previousFrame, !6 = $previousObject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'debug_backtrace'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                         $7      
          3        ASSIGN                                                   !0, $7
    5     4        INIT_FCALL                                               'array_shift'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                                 
    7     7        INIT_FCALL                                               'array_shift'
          8        SEND_REF                                                 !0
          9        DO_ICALL                                         $10     
         10        ASSIGN                                                   !1, $10
    8    11        TYPE_CHECK                                    2          !1
         12      > JMPZ                                                     ~12, ->14
    9    13    > > RETURN                                                   null
   12    14    >   FETCH_DIM_R                                      ~13     !1, 'function'
         15        ASSIGN                                                   !2, ~13
   13    16        IN_ARRAY                                         ~15     !2, <array>
         17        BOOL_NOT                                         ~16     ~15
         18      > JMPZ                                                     ~16, ->20
   14    19    > > RETURN                                                   null
   17    20    >   FETCH_DIM_IS                                     ~17     !1, 'object'
         21        COALESCE                                         ~18     ~17
         22        QM_ASSIGN                                        ~18     null
         23        ASSIGN                                                   !3, ~18
   18    24        FETCH_DIM_R                                      ~20     !1, 'args'
         25        FETCH_DIM_R                                      ~21     ~20, 0
         26        ASSIGN                                                   !4, ~21
   20    27      > FE_RESET_R                                       $23     !0, ->53
         28    > > FE_FETCH_R                                               $23, !5, ->53
   21    29    >   FETCH_DIM_IS                                     ~24     !5, 'object'
         30        COALESCE                                         ~25     ~24
         31        QM_ASSIGN                                        ~25     null
         32        ASSIGN                                                   !6, ~25
   22    33        FETCH_DIM_R                                      ~27     !5, 'function'
         34        IS_NOT_IDENTICAL                                 ~28     !2, ~27
         35      > JMPNZ_EX                                         ~28     ~28, ->38
   23    36    >   IS_NOT_IDENTICAL                                 ~29     !6, !3
         37        BOOL                                             ~28     ~29
         38    > > JMPNZ_EX                                         ~28     ~28, ->43
   24    39    >   FETCH_DIM_R                                      ~30     !5, 'args'
         40        FETCH_DIM_R                                      ~31     ~30, 0
         41        IS_NOT_IDENTICAL                                 ~32     !4, ~31
         42        BOOL                                             ~28     ~32
         43    > > JMPZ                                                     ~28, ->52
   25    44    >   TYPE_CHECK                                  1020          !6
         45      > JMPZ                                                     ~33, ->49
   26    46    >   FETCH_CLASS_NAME                                 ~34     !6
         47        QM_ASSIGN                                        ~35     ~34
         48      > JMP                                                      ->50
   27    49    >   QM_ASSIGN                                        ~35     null
         50    >   FE_FREE                                                  $23
         51      > RETURN                                                   ~35
   20    52    > > JMP                                                      ->28
         53    >   FE_FREE                                                  $23
   31    54      > RETURN                                                   null
   32    55*     > RETURN                                                   null

End of function get_calling_scope

Class Foo:
Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6Ua8t
function name:  __get
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'get_calling_scope'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_ICALL                                                 
   37     6      > RETURN                                                   ''
   38     7*     > RETURN                                                   null

End of function __get

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6Ua8t
function name:  test
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1        FREE                                                     ~0
   42     2      > RETURN                                                   null

End of function test

End of class Foo.

Class Bar:
Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6Ua8t
function name:  __get
number of ops:  6
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   47     1        INIT_STATIC_METHOD_CALL                                  '__get'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   48     4      > RETURN                                                   ''
   49     5*     > RETURN                                                   null

End of function __get

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6Ua8t
function name:  test
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1        FREE                                                     ~0
   42     2      > RETURN                                                   null

End of function test

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.58 ms | 1011 KiB | 17 Q