3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait X { public function test() {echo 'this is from A';} } class A { use X; } class B extends A { public function test() {echo 'this is from B';} } class C extends B { public function run() { $this->test(); // this outputs 'this is from A' !!! } // however if I include this function, it works correctly by echoing 'this is from B' // public function test() { // parent::test(); // } // whats even more weird, is that an almost identical class D works correctly } (new C())->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejRtn
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'a'
   12     1        DECLARE_CLASS                                            'b', 'a'
   16     2        DECLARE_CLASS                                            'c', 'b'
   29     3        NEW                                              $0      'C'
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $0, 'run'
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Class X:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejRtn
function name:  test
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ECHO                                                     'this+is+from+A'
          1      > RETURN                                                   null

End of function test

End of class X.

Class A: [no user functions]
Class B:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejRtn
function name:  test
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ECHO                                                     'this+is+from+B'
          1      > RETURN                                                   null

End of function test

End of class B.

Class C:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejRtn
function name:  run
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_METHOD_CALL                                         'test'
          1        DO_FCALL                                      0          
   19     2      > RETURN                                                   null

End of function run

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.89 ms | 1007 KiB | 13 Q