3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test{ static $count = 0; static $instance; /* Attempting to call method() from a non-static method inside the object : * "->" and "::" are 'overriden' by the method's context, * the object context in this case. * __call() is used in both calls. */ public function __construct(){ $this->method('from __construct() in object context ($this->)'); Test::method( 'from __construct() in class context (Test::)'); } public function __call($name, $arguments){ switch($name){ case 'method': self::magicMethod($arguments[0].' __call()'); } } public static function __callStatic($name, $arguments){ switch($name){ case 'method': self::magicMethod($arguments[0].' __callStatic()'); } } public static function magicMethod($arg){ Test::$count++; echo('Call '. self::$count.' : '.$arg."\n"); } /* Attempting to call method() from a non-static method inside the object : * "->" and "::" are 'overriden' by the method's context, * the object context in this case. * __call() is used in both calls. */ public function notMagic(){ $this->method('from notMagic() in object context ($this->)'); Test::method( 'from notMagic() in class context (Test::)'); } /* Calling method() from a static method inside the class : * "->" and "::" work as expected, * __call() is used in the first call. * __callStatic() is used in the second call. */ public static function staticNotMagic(){ Test::$instance->method('from staticNotMagic() in object context (Test::$instance->)'); Test::method('from staticNotMagic() in class context (Test::)'); } } //Behaves oddly (see method comments) $test = new Test(); $test->notMagic(); //Behaves as expected Test::$instance = $test; Test::staticNotMagic(); $test->method('from outside in object context ($test->)'); Test::method( 'from outside in class context (Test::)'); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbFTO
function name:  (null)
number of ops:  16
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   NEW                                              $1      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   62     3        INIT_METHOD_CALL                                         !0, 'notMagic'
          4        DO_FCALL                                      0          
   64     5        ASSIGN_STATIC_PROP                                       'instance', 'Test'
          6        OP_DATA                                                  !0
   65     7        INIT_STATIC_METHOD_CALL                                  'Test', 'staticNotMagic'
          8        DO_FCALL                                      0          
   66     9        INIT_METHOD_CALL                                         !0, 'method'
         10        SEND_VAL_EX                                              'from+outside+in+object+context+%28%24test-%3E%29'
         11        DO_FCALL                                      0          
   67    12        INIT_STATIC_METHOD_CALL                                  'Test', 'method'
         13        SEND_VAL_EX                                              'from+outside+in+class+context+++%28Test%3A%3A%29'
         14        DO_FCALL                                      0          
   69    15      > RETURN                                                   1

Class Test:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbFTO
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_METHOD_CALL                                         'method'
          1        SEND_VAL_EX                                              'from+__construct%28%29+in+object+context+%28%24this-%3E%29'
          2        DO_FCALL                                      0          
   15     3        INIT_STATIC_METHOD_CALL                                  'Test', 'method'
          4        SEND_VAL_EX                                              'from+__construct%28%29+in+class+context+++%28Test%3A%3A%29'
          5        DO_FCALL                                      0          
   16     6      > RETURN                                                   null

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbFTO
function name:  __call
number of ops:  11
compiled vars:  !0 = $name, !1 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        IS_EQUAL                                                 !0, 'method'
          3      > JMPNZ                                                    ~2, ->5
          4    > > JMP                                                      ->10
   21     5    >   INIT_STATIC_METHOD_CALL                                  'magicMethod'
          6        FETCH_DIM_R                                      ~3      !1, 0
          7        CONCAT                                           ~4      ~3, '+__call%28%29'
          8        SEND_VAL_EX                                              ~4
          9        DO_FCALL                                      0          
   23    10    > > RETURN                                                   null

End of function __call

Function __callstatic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbFTO
function name:  __callStatic
number of ops:  11
compiled vars:  !0 = $name, !1 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        IS_EQUAL                                                 !0, 'method'
          3      > JMPNZ                                                    ~2, ->5
          4    > > JMP                                                      ->10
   28     5    >   INIT_STATIC_METHOD_CALL                                  'magicMethod'
          6        FETCH_DIM_R                                      ~3      !1, 0
          7        CONCAT                                           ~4      ~3, '+__callStatic%28%29'
          8        SEND_VAL_EX                                              ~4
          9        DO_FCALL                                      0          
   31    10    > > RETURN                                                   null

End of function __callstatic

Function magicmethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbFTO
function name:  magicMethod
number of ops:  9
compiled vars:  !0 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        PRE_INC_STATIC_PROP                                      'count', 'Test'
   36     2        FETCH_STATIC_PROP_R          unknown             ~2      'count'
          3        CONCAT                                           ~3      'Call+', ~2
          4        CONCAT                                           ~4      ~3, '+%3A+'
          5        CONCAT                                           ~5      ~4, !0
          6        CONCAT                                           ~6      ~5, '%0A'
          7        ECHO                                                     ~6
   37     8      > RETURN                                                   null

End of function magicmethod

Function notmagic:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbFTO
function name:  notMagic
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   INIT_METHOD_CALL                                         'method'
          1        SEND_VAL_EX                                              'from+notMagic%28%29+in+object+context+%28%24this-%3E%29'
          2        DO_FCALL                                      0          
   46     3        INIT_STATIC_METHOD_CALL                                  'Test', 'method'
          4        SEND_VAL_EX                                              'from+notMagic%28%29+in+class+context+++%28Test%3A%3A%29'
          5        DO_FCALL                                      0          
   47     6      > RETURN                                                   null

End of function notmagic

Function staticnotmagic:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbFTO
function name:  staticNotMagic
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instance'
          1        INIT_METHOD_CALL                                         ~0, 'method'
          2        SEND_VAL_EX                                              'from+staticNotMagic%28%29+in+object+context+%28Test%3A%3A%24instance-%3E%29'
          3        DO_FCALL                                      0          
   56     4        INIT_STATIC_METHOD_CALL                                  'Test', 'method'
          5        SEND_VAL_EX                                              'from+staticNotMagic%28%29+in+class+context+++++++++++++%28Test%3A%3A%29'
          6        DO_FCALL                                      0          
   57     7      > RETURN                                                   null

End of function staticnotmagic

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.83 ms | 1403 KiB | 13 Q