3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Vehicle { public function setSpeedLimit(Float $limit) : Car; public function setManufacturer(String $manufacturer) : MethodOfTransport; } interface NonVehicle { public function addSaddle() : Bicycle; public function setManufacturer(String $manufacturer) : MethodOfTransport; } abstract class MethodOfTransport { public function setManufacturer(String $manufacturer) : MethodOfTransport { return $this; } } class Bicycle extends MethodOfTransport implements NonVehicle { public function addSaddle() : Bicycle { return $this; } } class Car extends MethodOfTransport implements Vehicle { public function setSpeedLimit(Float $limit) : Car { return $this; } } $b = (new Bicycle())->setManufacturer( 'Foo' )->addSaddle(); $c = (new Car())->setManufacturer( 'Bar' )->setSpeedLimit( 140 ); interface VehicleServiceInterface { public function create(MethodOfTransport $t) : Void; } class VehicleService implements VehicleServiceInterface { public function create(MethodOfTransport $t) : Void { if (!$t instanceof Vehicle) throw new Exception( 'Cannot create a Vehicle on a NonVehicle instance.' ); echo 'Created'; } } (new VehicleService())->create( $c ); // Works (new VehicleService())->create( $b ); // Throws Exception
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccumv
function name:  (null)
number of ops:  31
compiled vars:  !0 = $b, !1 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   DECLARE_CLASS                                            'bicycle', 'methodoftransport'
   23     1        DECLARE_CLASS                                            'car', 'methodoftransport'
   28     2        NEW                                              $2      'Bicycle'
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $2, 'setManufacturer'
          5        SEND_VAL_EX                                              'Foo'
          6        DO_FCALL                                      0  $4      
          7        INIT_METHOD_CALL                                         $4, 'addSaddle'
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !0, $5
   29    10        NEW                                              $7      'Car'
         11        DO_FCALL                                      0          
         12        INIT_METHOD_CALL                                         $7, 'setManufacturer'
         13        SEND_VAL_EX                                              'Bar'
         14        DO_FCALL                                      0  $9      
         15        INIT_METHOD_CALL                                         $9, 'setSpeedLimit'
         16        SEND_VAL_EX                                              140
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !1, $10
   36    19        DECLARE_CLASS                                            'vehicleservice'
   47    20        NEW                                              $12     'VehicleService'
         21        DO_FCALL                                      0          
         22        INIT_METHOD_CALL                                         $12, 'create'
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0          
   48    25        NEW                                              $15     'VehicleService'
         26        DO_FCALL                                      0          
         27        INIT_METHOD_CALL                                         $15, 'create'
         28        SEND_VAR_EX                                              !0
         29        DO_FCALL                                      0          
         30      > RETURN                                                   1

Class Vehicle:
Function setspeedlimit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccumv
function name:  setSpeedLimit
number of ops:  3
compiled vars:  !0 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        VERIFY_RETURN_TYPE                                       
          2      > RETURN                                                   null

End of function setspeedlimit

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

End of function setmanufacturer

End of class Vehicle.

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

End of function addsaddle

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

End of function setmanufacturer

End of class NonVehicle.

Class MethodOfTransport:
Function setmanufacturer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccumv
function name:  setManufacturer
number of ops:  6
compiled vars:  !0 = $manufacturer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        FETCH_THIS                                       ~1      
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
          4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function setmanufacturer

End of class MethodOfTransport.

Class Bicycle:
Function addsaddle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccumv
function name:  addSaddle
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_THIS                                       ~0      
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
          3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function addsaddle

End of class Bicycle.

Class Car:
Function setspeedlimit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ccumv
function name:  setSpeedLimit
number of ops:  6
compiled vars:  !0 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        FETCH_THIS                                       ~1      
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
          4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function setspeedlimit

End of class Car.

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

End of function create

End of class VehicleServiceInterface.

Class VehicleService:
Function create:
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/ccumv
function name:  create
number of ops:  10
compiled vars:  !0 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        INSTANCEOF                                       ~1      !0, 'Vehicle'
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->8
   41     4    >   NEW                                              $3      'Exception'
          5        SEND_VAL_EX                                              'Cannot+create+a+Vehicle+on+a+NonVehicle+instance.'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   43     8    >   ECHO                                                     'Created'
   44     9      > RETURN                                                   null

End of function create

End of class VehicleService.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.8 ms | 1451 KiB | 13 Q