3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait implementedBar { public function bar($a){ echo "a"; } } trait abstractBar { abstract protected function bar($a); } abstract class parentImplemented { use implementedBar; } class childAbstract extends parentImplemented { use abstractBar; } //what would happen if you copy/pasted the traits into their classes //the below classes would definitely cause an error /** abstract class parentImplemented { public function bar($a){ echo "a"; } } class childAbstract extends parentImplemented { abstract protected function bar($a); } **/ //below will just work, but we can't really see that implementedBar::bar is an implementation of abstractBar::bar //instead of it being a replacement, or abstractBar::bar just getting ignored echo "Example 1:".PHP_EOL; $b = new childAbstract; $b->bar([]); //////////////////////////////////// trait implementedBarTH { public function bar(array $a){ echo "a"; } } trait abstractBarTH { abstract protected function bar(int $a); } abstract class parentImplementedTH { use implementedBarTH; } class childAbstractTH extends parentImplementedTH { use abstractBarTH; } //again, a version with the traits copy/pasted into their classes //definitely will cause an error /** abstract class parentImplementedTH { public function bar(array $a){ echo "a"; } } class childAbstractTH extends parentImplementedTH { abstract protected function bar(int $a); } **/ //This will give us an error related to mismatched type hints. //This shows that the method in the trait used in the parent class is definitely //acting as an implementation of the abstract class from the trait used in the child class $b = new childAbstractTH; $b->bar([]); /*** You'll need to comment out 53-59, 80-81 in order to produce an error for the items below ***/ ////////////////////////////////////////////////////////////// class childBothTH { use abstractBarTH, implementedBarTH; } //a version with the traits copy/pasted into the class //definitely will cause an error /** class childBothTH { abstract protected function bar(int $a); public function bar(array $a){ echo "a"; } } **/ //This will give us an error related to mismatched type hints. //This shows that the method in the trait that was implemented is definitely //acting as an implementation of the abstract class from the other trait $b = new childBothTH; $b->bar([]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKoTY
function name:  (null)
number of ops:  25
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   DECLARE_CLASS                                            'parentimplemented'
   17     1        DECLARE_CLASS                                            'childabstract', 'parentimplemented'
   37     2        ECHO                                                     'Example+1%3A%0A'
   38     3        NEW                                              $1      'childAbstract'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   39     6        INIT_METHOD_CALL                                         !0, 'bar'
          7        SEND_VAL_EX                                              <array>
          8        DO_FCALL                                      0          
   53     9        DECLARE_CLASS                                            'parentimplementedth'
   57    10        DECLARE_CLASS                                            'childabstractth', 'parentimplementedth'
   80    11        NEW                                              $5      'childAbstractTH'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !0, $5
   81    14        INIT_METHOD_CALL                                         !0, 'bar'
         15        SEND_VAL_EX                                              <array>
         16        DO_FCALL                                      0          
   87    17        DECLARE_CLASS                                            'childbothth'
  108    18        NEW                                              $9      'childBothTH'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !0, $9
  109    21        INIT_METHOD_CALL                                         !0, 'bar'
         22        SEND_VAL_EX                                              <array>
         23        DO_FCALL                                      0          
         24      > RETURN                                                   1

Class implementedBar:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKoTY
function name:  bar
number of ops:  3
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ECHO                                                     'a'
    6     2      > RETURN                                                   null

End of function bar

End of class implementedBar.

Class abstractBar:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKoTY
function name:  bar
number of ops:  2
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function bar

End of class abstractBar.

Class parentImplemented: [no user functions]
Class childAbstract: [no user functions]
Class implementedBarTH:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKoTY
function name:  bar
number of ops:  3
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        ECHO                                                     'a'
   46     2      > RETURN                                                   null

End of function bar

End of class implementedBarTH.

Class abstractBarTH:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKoTY
function name:  bar
number of ops:  2
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function bar

End of class abstractBarTH.

Class parentImplementedTH: [no user functions]
Class childAbstractTH: [no user functions]
Class childBothTH: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.6 ms | 1403 KiB | 13 Q