3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); interface I { public function example(); } class A implements I { public function example(): int { return 123; } // compatible with I::example } class B extends A { public function example(): string { return "string"; } // compatible with I::example } function accepts_i_expects_any(I $i) { var_dump($i->example()); } accepts_i_expects_any(new B); // receives string, no problem function accepts_a_expects_int(A $a) { var_dump($a->example()); } accepts_a_expects_int(new B); // receives string, problem
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TUbfJ
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'a'
   11     1        DECLARE_CLASS                                            'b', 'a'
   18     2        INIT_FCALL                                               'accepts_i_expects_any'
          3        NEW                                              $0      'B'
          4        DO_FCALL                                      0          
          5        SEND_VAR                                                 $0
          6        DO_FCALL                                      0          
   23     7        INIT_FCALL                                               'accepts_a_expects_int'
          8        NEW                                              $3      'B'
          9        DO_FCALL                                      0          
         10        SEND_VAR                                                 $3
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function accepts_i_expects_any:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TUbfJ
function name:  accepts_i_expects_any
number of ops:  7
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'var_dump'
          2        INIT_METHOD_CALL                                         !0, 'example'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_ICALL                                                 
   17     6      > RETURN                                                   null

End of function accepts_i_expects_any

Function accepts_a_expects_int:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TUbfJ
function name:  accepts_a_expects_int
number of ops:  7
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_FCALL                                               'var_dump'
          2        INIT_METHOD_CALL                                         !0, 'example'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_ICALL                                                 
   22     6      > RETURN                                                   null

End of function accepts_a_expects_int

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

End of function example

End of class I.

Class A:
Function example:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TUbfJ
function name:  example
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E > > RETURN                                                   123
          1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function example

End of class A.

Class B:
Function example:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TUbfJ
function name:  example
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E > > RETURN                                                   'string'
          1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function example

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.69 ms | 1402 KiB | 17 Q