3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Banana {} class Football {} abstract class Point { abstract public function add(Point $other); abstract public function subtract(Point $other); } class Vector2 extends Point { public function add(Point|Banana $other) { if (!$other instanceof Banana) { throw new TypeError("Point only allowed to prevent compiler errors"); } // ...rest of the function } public function subtract(Point|Football $other) { if (!$other instanceof Football) { throw new TypeError("Point only allowed to prevent compiler errors"); } // ...rest of the function } } (new Vector2())->subtract( new Football() );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pTdMg
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $0      'Vector2'
          1        DO_FCALL                                      0          
          2        INIT_METHOD_CALL                                         $0, 'subtract'
          3        NEW                                              $2      'Football'
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Class Banana: [no user functions]
Class Football: [no user functions]
Class Point:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pTdMg
function name:  add
number of ops:  2
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function add

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

End of function subtract

End of class Point.

Class Vector2:
Function add:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pTdMg
function name:  add
number of ops:  9
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INSTANCEOF                                       ~1      !0, 'Banana'
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->8
   14     4    >   NEW                                              $3      'TypeError'
          5        SEND_VAL_EX                                              'Point+only+allowed+to+prevent+compiler+errors'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   17     8    > > RETURN                                                   null

End of function add

Function subtract:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pTdMg
function name:  subtract
number of ops:  9
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INSTANCEOF                                       ~1      !0, 'Football'
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->8
   20     4    >   NEW                                              $3      'TypeError'
          5        SEND_VAL_EX                                              'Point+only+allowed+to+prevent+compiler+errors'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   23     8    > > RETURN                                                   null

End of function subtract

End of class Vector2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.75 ms | 1007 KiB | 13 Q