3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Invalid example class Animal { public function eat(){} } class Cat extends Animal { public function meow(){ echo "meow"; } } class A { function foo(): Animal { return new Animal(); } } class B extends A { function foo(): Cat { return new Cat(); } } if (rand(0, 1)) { $object = new A; } else { $object = new B; } $animal = $object->foo(); $animal->meow(); // This code fails %50 of the time as not all animals can meow.
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WaOiP
function name:  (null)
number of ops:  18
compiled vars:  !0 = $object, !1 = $animal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 1
          3        DO_ICALL                                         $2      
          4      > JMPZ                                                     $2, ->9
   29     5    >   NEW                                              $3      'A'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $3
          8      > JMP                                                      ->12
   32     9    >   NEW                                              $6      'B'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !0, $6
   35    12    >   INIT_METHOD_CALL                                         !0, 'foo'
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !1, $9
   36    15        INIT_METHOD_CALL                                         !1, 'meow'
         16        DO_FCALL                                      0          
   38    17      > RETURN                                                   1

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

End of function eat

End of class Animal.

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

End of function meow

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

End of function eat

End of class Cat.

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

End of function foo

End of class A.

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

End of function foo

End of class B.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.97 ms | 1400 KiB | 15 Q