3v4l.org

run code in 300+ PHP versions simultaneously
<?php function super(... $args) { $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 2); if(($object = $trace[1]["object"]) || ($object = $trace[1]["class"])) { $method = $trace[1]["function"]; $parent = get_parent_class($object); if(method_exists($parent, $method)) { $method = new ReflectionMethod($parent, $method); return $method->invoke(is_object($object) ? $object : NULL); } else throw new BadMethodCallException("Method " . $parent . "::" . $method ." does not exist."); } else throw new BadFunctionCallException("super() can only be called from a class context."); } class HasSuper { protected function super(... $args) { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $method = $trace[1]["function"]; $parent = get_parent_class($this); if(method_exists($parent, $method)) { $method = new ReflectionMethod($parent, $method); $method->invoke($this); } else throw new BadMethodCallException("Method " . $callback . " does not exist."); } } class Foo extends HasSuper { public function hello() { echo("Hello World!" . PHP_EOL); } } class Bar extends Foo { public function hello() { $this->super(); super(); } } $bar = new Bar; $bar->hello();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2qPQv
function name:  (null)
number of ops:  6
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   NEW                                              $1      'Bar'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   52     3        INIT_METHOD_CALL                                         !0, 'hello'
          4        DO_FCALL                                      0          
          5      > RETURN                                                   1

Function super:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 51
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 42
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
filename:       /in/2qPQv
function name:  super
number of ops:  56
compiled vars:  !0 = $args, !1 = $trace, !2 = $object, !3 = $method, !4 = $parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_VARIADIC                                    !0      
    4     1        INIT_FCALL                                               'debug_backtrace'
          2        SEND_VAL                                                 3
          3        SEND_VAL                                                 2
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
    5     6        FETCH_DIM_R                                      ~7      !1, 1
          7        FETCH_DIM_R                                      ~8      ~7, 'object'
          8        ASSIGN                                           ~9      !2, ~8
          9      > JMPNZ_EX                                         ~9      ~9, ->14
         10    >   FETCH_DIM_R                                      ~10     !1, 1
         11        FETCH_DIM_R                                      ~11     ~10, 'class'
         12        ASSIGN                                           ~12     !2, ~11
         13        BOOL                                             ~9      ~12
         14    > > JMPZ                                                     ~9, ->51
    7    15    >   FETCH_DIM_R                                      ~13     !1, 1
         16        FETCH_DIM_R                                      ~14     ~13, 'function'
         17        ASSIGN                                                   !3, ~14
    8    18        INIT_FCALL                                               'get_parent_class'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $16     
         21        ASSIGN                                                   !4, $16
    9    22        INIT_FCALL                                               'method_exists'
         23        SEND_VAR                                                 !4
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $18     
         26      > JMPZ                                                     $18, ->42
   11    27    >   NEW                                              $19     'ReflectionMethod'
         28        SEND_VAR_EX                                              !4
         29        SEND_VAR_EX                                              !3
         30        DO_FCALL                                      0          
         31        ASSIGN                                                   !3, $19
   12    32        INIT_METHOD_CALL                                         !3, 'invoke'
         33        TYPE_CHECK                                  256          !2
         34      > JMPZ                                                     ~22, ->37
         35    >   QM_ASSIGN                                        ~23     !2
         36      > JMP                                                      ->38
         37    >   QM_ASSIGN                                        ~23     null
         38    >   SEND_VAL_EX                                              ~23
         39        DO_FCALL                                      0  $24     
         40      > RETURN                                                   $24
         41*       JMP                                                      ->50
   15    42    >   NEW                                              $25     'BadMethodCallException'
         43        CONCAT                                           ~26     'Method+', !4
         44        CONCAT                                           ~27     ~26, '%3A%3A'
         45        CONCAT                                           ~28     ~27, !3
         46        CONCAT                                           ~29     ~28, '+does+not+exist.'
         47        SEND_VAL_EX                                              ~29
         48        DO_FCALL                                      0          
         49      > THROW                                         0          $25
         50*       JMP                                                      ->55
   18    51    >   NEW                                              $31     'BadFunctionCallException'
         52        SEND_VAL_EX                                              'super%28%29+can+only+be+called+from+a+class+context.'
         53        DO_FCALL                                      0          
         54      > THROW                                         0          $31
   19    55*     > RETURN                                                   null

End of function super

Class HasSuper:
Function super:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 29
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/2qPQv
function name:  super
number of ops:  36
compiled vars:  !0 = $args, !1 = $trace, !2 = $method, !3 = $parent, !4 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_VARIADIC                                    !0      
   24     1        INIT_FCALL                                               'debug_backtrace'
          2        SEND_VAL                                                 2
          3        SEND_VAL                                                 2
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   25     6        FETCH_DIM_R                                      ~7      !1, 1
          7        FETCH_DIM_R                                      ~8      ~7, 'function'
          8        ASSIGN                                                   !2, ~8
   26     9        INIT_FCALL                                               'get_parent_class'
         10        FETCH_THIS                                       ~10     
         11        SEND_VAL                                                 ~10
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !3, $11
   27    14        INIT_FCALL                                               'method_exists'
         15        SEND_VAR                                                 !3
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $13     
         18      > JMPZ                                                     $13, ->29
   29    19    >   NEW                                              $14     'ReflectionMethod'
         20        SEND_VAR_EX                                              !3
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !2, $14
   30    24        INIT_METHOD_CALL                                         !2, 'invoke'
         25        FETCH_THIS                                       $17     
         26        SEND_VAR_EX                                              $17
         27        DO_FCALL                                      0          
         28      > JMP                                                      ->35
   33    29    >   NEW                                              $19     'BadMethodCallException'
         30        CONCAT                                           ~20     'Method+', !4
         31        CONCAT                                           ~21     ~20, '+does+not+exist.'
         32        SEND_VAL_EX                                              ~21
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $19
   34    35    > > RETURN                                                   null

End of function super

End of class HasSuper.

Class Foo:
Function hello:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2qPQv
function name:  hello
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ECHO                                                     'Hello+World%21%0A'
   41     1      > RETURN                                                   null

End of function hello

Function super:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 29
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/2qPQv
function name:  super
number of ops:  36
compiled vars:  !0 = $args, !1 = $trace, !2 = $method, !3 = $parent, !4 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_VARIADIC                                    !0      
   24     1        INIT_FCALL                                               'debug_backtrace'
          2        SEND_VAL                                                 2
          3        SEND_VAL                                                 2
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   25     6        FETCH_DIM_R                                      ~7      !1, 1
          7        FETCH_DIM_R                                      ~8      ~7, 'function'
          8        ASSIGN                                                   !2, ~8
   26     9        INIT_FCALL                                               'get_parent_class'
         10        FETCH_THIS                                       ~10     
         11        SEND_VAL                                                 ~10
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !3, $11
   27    14        INIT_FCALL                                               'method_exists'
         15        SEND_VAR                                                 !3
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $13     
         18      > JMPZ                                                     $13, ->29
   29    19    >   NEW                                              $14     'ReflectionMethod'
         20        SEND_VAR_EX                                              !3
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !2, $14
   30    24        INIT_METHOD_CALL                                         !2, 'invoke'
         25        FETCH_THIS                                       $17     
         26        SEND_VAR_EX                                              $17
         27        DO_FCALL                                      0          
         28      > JMP                                                      ->35
   33    29    >   NEW                                              $19     'BadMethodCallException'
         30        CONCAT                                           ~20     'Method+', !4
         31        CONCAT                                           ~21     ~20, '+does+not+exist.'
         32        SEND_VAL_EX                                              ~21
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $19
   34    35    > > RETURN                                                   null

End of function super

End of class Foo.

Class Bar:
Function hello:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2qPQv
function name:  hello
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_METHOD_CALL                                         'super'
          1        DO_FCALL                                      0          
   48     2        INIT_FCALL                                               'super'
          3        DO_FCALL                                      0          
   49     4      > RETURN                                                   null

End of function hello

Function super:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 29
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/2qPQv
function name:  super
number of ops:  36
compiled vars:  !0 = $args, !1 = $trace, !2 = $method, !3 = $parent, !4 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_VARIADIC                                    !0      
   24     1        INIT_FCALL                                               'debug_backtrace'
          2        SEND_VAL                                                 2
          3        SEND_VAL                                                 2
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   25     6        FETCH_DIM_R                                      ~7      !1, 1
          7        FETCH_DIM_R                                      ~8      ~7, 'function'
          8        ASSIGN                                                   !2, ~8
   26     9        INIT_FCALL                                               'get_parent_class'
         10        FETCH_THIS                                       ~10     
         11        SEND_VAL                                                 ~10
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !3, $11
   27    14        INIT_FCALL                                               'method_exists'
         15        SEND_VAR                                                 !3
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $13     
         18      > JMPZ                                                     $13, ->29
   29    19    >   NEW                                              $14     'ReflectionMethod'
         20        SEND_VAR_EX                                              !3
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !2, $14
   30    24        INIT_METHOD_CALL                                         !2, 'invoke'
         25        FETCH_THIS                                       $17     
         26        SEND_VAR_EX                                              $17
         27        DO_FCALL                                      0          
         28      > JMP                                                      ->35
   33    29    >   NEW                                              $19     'BadMethodCallException'
         30        CONCAT                                           ~20     'Method+', !4
         31        CONCAT                                           ~21     ~20, '+does+not+exist.'
         32        SEND_VAL_EX                                              ~21
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $19
   34    35    > > RETURN                                                   null

End of function super

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.3 ms | 1419 KiB | 20 Q