3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function get_self() { return new self(); } public function get_static() { return new static(); } } class B extends A {} class C { public function static_get_a_self() { return A::get_self(); } public function static_get_a_static() { return A::get_static(); } public function var_get_a_self() { $a = new A(); return $a->get_self(); } public function var_get_a_static() { $a = new A(); return $a->get_static(); } public function static_get_b_self() { return B::get_self(); } public function static_get_b_static() { return B::get_static(); } public function var_get_b_self() { $b = new B(); return $b->get_self(); } public function var_get_b_static() { $b = new B(); return $b->get_static(); } } $a = new A(); $b = new B(); $c = new C(); echo "Static calls: \n"; echo "B::get_self() ============= " . get_class(B::get_self()) . " | expected A \n"; echo "B::get_static() =========== " . get_class(B::get_static()) . " | expected B \n"; echo "A::get_static() =========== " . get_class(A::get_static()) . " | expected A \n"; echo "\n"; echo "Object Calls on A: \n"; echo '$a->get_self() ============ ' . get_class($a->get_self()) . " | expected A \n"; echo '$a->get_static() ========== ' . get_class($a->get_static()) . " | expected A \n"; echo "\n"; echo "Object Calls on B: \n"; echo '$b->get_self() ============ ' . get_class($b->get_self()) . " | expected A \n"; echo '$b->get_static() ========== ' . get_class($b->get_static()) . " | expected B \n"; echo "\n"; echo "C Object Calls on A: \n"; echo "Internally against A::{call}\n"; echo '$c->static_get_a_self() === ' . get_class($c->static_get_a_self()) . " | expected A \n"; echo '$c->static_get_a_static() = ' . get_class($c->static_get_a_static()) . " | expected A < Whoa! \n"; echo "Internally against \$a = new A();\n"; echo '$c->var_get_a_self() ====== ' . get_class($c->var_get_a_self()) . " | expected A \n"; echo '$c->var_get_a_static() ==== ' . get_class($c->var_get_a_static()) . " | expected A \n"; echo "\n"; echo "C Object Calls on B: \n"; echo "Internally against B::{call}\n"; echo '$c->static_get_b_self() === ' . get_class($c->static_get_b_self()) . " | expected A \n"; echo '$c->static_get_b_static() = ' . get_class($c->static_get_b_static()) . " | expected B < Whoa! \n"; echo "Internally against \$b = new B();\n"; echo '$c->var_get_b_self() ====== ' . get_class($c->var_get_b_self()) . " | expected A \n"; echo '$c->var_get_b_static() ==== ' . get_class($c->var_get_b_static()) . " | expected B \n"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  (null)
number of ops:  113
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   NEW                                              $3      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   55     3        NEW                                              $6      'B'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   56     6        NEW                                              $9      'C'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $9
   58     9        ECHO                                                     'Static+calls%3A+%0A'
   59    10        INIT_STATIC_METHOD_CALL                                  'B', 'get_self'
         11        DO_FCALL                                      0  $12     
         12        GET_CLASS                                        ~13     $12
         13        CONCAT                                           ~14     'B%3A%3Aget_self%28%29+%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D+', ~13
         14        CONCAT                                           ~15     ~14, '+%7C+expected+A+%0A'
         15        ECHO                                                     ~15
   60    16        INIT_STATIC_METHOD_CALL                                  'B', 'get_static'
         17        DO_FCALL                                      0  $16     
         18        GET_CLASS                                        ~17     $16
         19        CONCAT                                           ~18     'B%3A%3Aget_static%28%29+%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D+', ~17
         20        CONCAT                                           ~19     ~18, '+%7C+expected+B+%0A'
         21        ECHO                                                     ~19
   61    22        INIT_STATIC_METHOD_CALL                                  'A', 'get_static'
         23        DO_FCALL                                      0  $20     
         24        GET_CLASS                                        ~21     $20
         25        CONCAT                                           ~22     'A%3A%3Aget_static%28%29+%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D+', ~21
         26        CONCAT                                           ~23     ~22, '+%7C+expected+A+%0A'
         27        ECHO                                                     ~23
   62    28        ECHO                                                     '%0A'
   64    29        ECHO                                                     'Object+Calls+on+A%3A+%0A'
   65    30        INIT_METHOD_CALL                                         !0, 'get_self'
         31        DO_FCALL                                      0  $24     
         32        GET_CLASS                                        ~25     $24
         33        CONCAT                                           ~26     '%24a-%3Eget_self%28%29+%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D+', ~25
         34        CONCAT                                           ~27     ~26, '+%7C+expected+A+%0A'
         35        ECHO                                                     ~27
   66    36        INIT_METHOD_CALL                                         !0, 'get_static'
         37        DO_FCALL                                      0  $28     
         38        GET_CLASS                                        ~29     $28
         39        CONCAT                                           ~30     '%24a-%3Eget_static%28%29+%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D+', ~29
         40        CONCAT                                           ~31     ~30, '+%7C+expected+A+%0A'
         41        ECHO                                                     ~31
   67    42        ECHO                                                     '%0A'
   69    43        ECHO                                                     'Object+Calls+on+B%3A+%0A'
   70    44        INIT_METHOD_CALL                                         !1, 'get_self'
         45        DO_FCALL                                      0  $32     
         46        GET_CLASS                                        ~33     $32
         47        CONCAT                                           ~34     '%24b-%3Eget_self%28%29+%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D+', ~33
         48        CONCAT                                           ~35     ~34, '+%7C+expected+A+%0A'
         49        ECHO                                                     ~35
   71    50        INIT_METHOD_CALL                                         !1, 'get_static'
         51        DO_FCALL                                      0  $36     
         52        GET_CLASS                                        ~37     $36
         53        CONCAT                                           ~38     '%24b-%3Eget_static%28%29+%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D+', ~37
         54        CONCAT                                           ~39     ~38, '+%7C+expected+B+%0A'
         55        ECHO                                                     ~39
   72    56        ECHO                                                     '%0A'
   74    57        ECHO                                                     'C+Object+Calls+on+A%3A+%0A'
   75    58        ECHO                                                     'Internally+against+A%3A%3A%7Bcall%7D%0A'
   76    59        INIT_METHOD_CALL                                         !2, 'static_get_a_self'
         60        DO_FCALL                                      0  $40     
         61        GET_CLASS                                        ~41     $40
         62        CONCAT                                           ~42     '%24c-%3Estatic_get_a_self%28%29+%3D%3D%3D+', ~41
         63        CONCAT                                           ~43     ~42, '+%7C+expected+A+%0A'
         64        ECHO                                                     ~43
   77    65        INIT_METHOD_CALL                                         !2, 'static_get_a_static'
         66        DO_FCALL                                      0  $44     
         67        GET_CLASS                                        ~45     $44
         68        CONCAT                                           ~46     '%24c-%3Estatic_get_a_static%28%29+%3D+', ~45
         69        CONCAT                                           ~47     ~46, '+%7C+expected+A+%3C+Whoa%21+%0A'
         70        ECHO                                                     ~47
   78    71        ECHO                                                     'Internally+against+%24a+%3D+new+A%28%29%3B%0A'
   79    72        INIT_METHOD_CALL                                         !2, 'var_get_a_self'
         73        DO_FCALL                                      0  $48     
         74        GET_CLASS                                        ~49     $48
         75        CONCAT                                           ~50     '%24c-%3Evar_get_a_self%28%29+%3D%3D%3D%3D%3D%3D+', ~49
         76        CONCAT                                           ~51     ~50, '+%7C+expected+A+%0A'
         77        ECHO                                                     ~51
   80    78        INIT_METHOD_CALL                                         !2, 'var_get_a_static'
         79        DO_FCALL                                      0  $52     
         80        GET_CLASS                                        ~53     $52
         81        CONCAT                                           ~54     '%24c-%3Evar_get_a_static%28%29+%3D%3D%3D%3D+', ~53
         82        CONCAT                                           ~55     ~54, '+%7C+expected+A+%0A'
         83        ECHO                                                     ~55
   81    84        ECHO                                                     '%0A'
   83    85        ECHO                                                     'C+Object+Calls+on+B%3A+%0A'
   84    86        ECHO                                                     'Internally+against+B%3A%3A%7Bcall%7D%0A'
   85    87        INIT_METHOD_CALL                                         !2, 'static_get_b_self'
         88        DO_FCALL                                      0  $56     
         89        GET_CLASS                                        ~57     $56
         90        CONCAT                                           ~58     '%24c-%3Estatic_get_b_self%28%29+%3D%3D%3D+', ~57
         91        CONCAT                                           ~59     ~58, '+%7C+expected+A+%0A'
         92        ECHO                                                     ~59
   86    93        INIT_METHOD_CALL                                         !2, 'static_get_b_static'
         94        DO_FCALL                                      0  $60     
         95        GET_CLASS                                        ~61     $60
         96        CONCAT                                           ~62     '%24c-%3Estatic_get_b_static%28%29+%3D+', ~61
         97        CONCAT                                           ~63     ~62, '+%7C+expected+B+%3C+Whoa%21+%0A'
         98        ECHO                                                     ~63
   87    99        ECHO                                                     'Internally+against+%24b+%3D+new+B%28%29%3B%0A'
   88   100        INIT_METHOD_CALL                                         !2, 'var_get_b_self'
        101        DO_FCALL                                      0  $64     
        102        GET_CLASS                                        ~65     $64
        103        CONCAT                                           ~66     '%24c-%3Evar_get_b_self%28%29+%3D%3D%3D%3D%3D%3D+', ~65
        104        CONCAT                                           ~67     ~66, '+%7C+expected+A+%0A'
        105        ECHO                                                     ~67
   89   106        INIT_METHOD_CALL                                         !2, 'var_get_b_static'
        107        DO_FCALL                                      0  $68     
        108        GET_CLASS                                        ~69     $68
        109        CONCAT                                           ~70     '%24c-%3Evar_get_b_static%28%29+%3D%3D%3D%3D+', ~69
        110        CONCAT                                           ~71     ~70, '+%7C+expected+B+%0A'
        111        ECHO                                                     ~71
   90   112      > RETURN                                                   1

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

End of function get_self

Function get_static:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  get_static
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   NEW                          static              $0      
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   10     3*     > RETURN                                                   null

End of function get_static

End of class A.

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

End of function get_self

Function get_static:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  get_static
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   NEW                          static              $0      
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   10     3*     > RETURN                                                   null

End of function get_static

End of class B.

Class C:
Function static_get_a_self:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  static_get_a_self
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_STATIC_METHOD_CALL                                  'A', 'get_self'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   18     3*     > RETURN                                                   null

End of function static_get_a_self

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

End of function static_get_a_static

Function var_get_a_self:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  var_get_a_self
number of ops:  7
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $1      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   26     3        INIT_METHOD_CALL                                         !0, 'get_self'
          4        DO_FCALL                                      0  $4      
          5      > RETURN                                                   $4
   27     6*     > RETURN                                                   null

End of function var_get_a_self

Function var_get_a_static:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  var_get_a_static
number of ops:  7
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   NEW                                              $1      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   31     3        INIT_METHOD_CALL                                         !0, 'get_static'
          4        DO_FCALL                                      0  $4      
          5      > RETURN                                                   $4
   32     6*     > RETURN                                                   null

End of function var_get_a_static

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

End of function static_get_b_self

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

End of function static_get_b_static

Function var_get_b_self:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  var_get_b_self
number of ops:  7
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   NEW                                              $1      'B'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   45     3        INIT_METHOD_CALL                                         !0, 'get_self'
          4        DO_FCALL                                      0  $4      
          5      > RETURN                                                   $4
   46     6*     > RETURN                                                   null

End of function var_get_b_self

Function var_get_b_static:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PecT
function name:  var_get_b_static
number of ops:  7
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   NEW                                              $1      'B'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   50     3        INIT_METHOD_CALL                                         !0, 'get_static'
          4        DO_FCALL                                      0  $4      
          5      > RETURN                                                   $4
   51     6*     > RETURN                                                   null

End of function var_get_b_static

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.97 ms | 1415 KiB | 13 Q