3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface GoAlgorithm { public function go(); } class GoByDrivingAlgorithm implements GoAlgorithm { public function go() { echo "Now I'm driving." .PHP_EOL; } } class GoByFlying implements GoAlgorithm { public function go() { echo "Now I'm flying." . PHP_EOL; } } class GoByFlyingFast implements GoAlgorithm { public function go() { echo "Now I'm flying fast" . PHP_EOL; } } class Vehicle { private $goAlgorithm; public function __construct(GoAlgorithm $goType = null) { $this->goAlgorithm = $goType; } public function setModeOfTransportation(GoAlgorithm $goType) { $this->goAlgorithm = $goType; } public function drive() { return $this->goAlgorithm->go(); } } // setter injection $streetRacer = new Vehicle(); $streetRacer->setModeOfTransportation(new GoByDrivingAlgorithm()); $formulaone = new Vehicle(); $formulaone->setModeOfTransportation(new GoByDrivingAlgorithm()); $helicopter = new Vehicle(); $helicopter->setModeOfTransportation(new GoByFlying()); $jets = new Vehicle(); $jets->setModeOfTransportation(new GoByFlyingFast()); $streetRacer->drive(); $formulaone->drive(); $helicopter->drive(); $jets->drive(); // constructor injection $streetRacer = new Vehicle(new GoByDrivingAlgorithm()); $formulaone = new Vehicle(new GoByDrivingAlgorithm()); $helicopter = new Vehicle(new GoByFlying()); $jets = new Vehicle(new GoByFlyingFast()); $streetRacer->drive(); $formulaone->drive(); $helicopter->drive(); $jets->drive();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY1gW
function name:  (null)
number of ops:  76
compiled vars:  !0 = $streetRacer, !1 = $formulaone, !2 = $helicopter, !3 = $jets
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'gobydrivingalgorithm'
   16     1        DECLARE_CLASS                                            'gobyflying'
   24     2        DECLARE_CLASS                                            'gobyflyingfast'
   52     3        NEW                                              $4      'Vehicle'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $4
   53     6        INIT_METHOD_CALL                                         !0, 'setModeOfTransportation'
          7        NEW                                              $7      'GoByDrivingAlgorithm'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $7
         10        DO_FCALL                                      0          
   54    11        NEW                                              $10     'Vehicle'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !1, $10
   55    14        INIT_METHOD_CALL                                         !1, 'setModeOfTransportation'
         15        NEW                                              $13     'GoByDrivingAlgorithm'
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $13
         18        DO_FCALL                                      0          
   56    19        NEW                                              $16     'Vehicle'
         20        DO_FCALL                                      0          
         21        ASSIGN                                                   !2, $16
   57    22        INIT_METHOD_CALL                                         !2, 'setModeOfTransportation'
         23        NEW                                              $19     'GoByFlying'
         24        DO_FCALL                                      0          
         25        SEND_VAR_NO_REF_EX                                       $19
         26        DO_FCALL                                      0          
   58    27        NEW                                              $22     'Vehicle'
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !3, $22
   59    30        INIT_METHOD_CALL                                         !3, 'setModeOfTransportation'
         31        NEW                                              $25     'GoByFlyingFast'
         32        DO_FCALL                                      0          
         33        SEND_VAR_NO_REF_EX                                       $25
         34        DO_FCALL                                      0          
   61    35        INIT_METHOD_CALL                                         !0, 'drive'
         36        DO_FCALL                                      0          
   62    37        INIT_METHOD_CALL                                         !1, 'drive'
         38        DO_FCALL                                      0          
   63    39        INIT_METHOD_CALL                                         !2, 'drive'
         40        DO_FCALL                                      0          
   64    41        INIT_METHOD_CALL                                         !3, 'drive'
         42        DO_FCALL                                      0          
   67    43        NEW                                              $32     'Vehicle'
         44        NEW                                              $33     'GoByDrivingAlgorithm'
         45        DO_FCALL                                      0          
         46        SEND_VAR_NO_REF_EX                                       $33
         47        DO_FCALL                                      0          
         48        ASSIGN                                                   !0, $32
   68    49        NEW                                              $37     'Vehicle'
         50        NEW                                              $38     'GoByDrivingAlgorithm'
         51        DO_FCALL                                      0          
         52        SEND_VAR_NO_REF_EX                                       $38
         53        DO_FCALL                                      0          
         54        ASSIGN                                                   !1, $37
   69    55        NEW                                              $42     'Vehicle'
         56        NEW                                              $43     'GoByFlying'
         57        DO_FCALL                                      0          
         58        SEND_VAR_NO_REF_EX                                       $43
         59        DO_FCALL                                      0          
         60        ASSIGN                                                   !2, $42
   70    61        NEW                                              $47     'Vehicle'
         62        NEW                                              $48     'GoByFlyingFast'
         63        DO_FCALL                                      0          
         64        SEND_VAR_NO_REF_EX                                       $48
         65        DO_FCALL                                      0          
         66        ASSIGN                                                   !3, $47
   72    67        INIT_METHOD_CALL                                         !0, 'drive'
         68        DO_FCALL                                      0          
   73    69        INIT_METHOD_CALL                                         !1, 'drive'
         70        DO_FCALL                                      0          
   74    71        INIT_METHOD_CALL                                         !2, 'drive'
         72        DO_FCALL                                      0          
   75    73        INIT_METHOD_CALL                                         !3, 'drive'
         74        DO_FCALL                                      0          
         75      > RETURN                                                   1

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

End of function go

End of class GoAlgorithm.

Class GoByDrivingAlgorithm:
Function go:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY1gW
function name:  go
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ECHO                                                     'Now+I%27m+driving.%0A'
   13     1      > RETURN                                                   null

End of function go

End of class GoByDrivingAlgorithm.

Class GoByFlying:
Function go:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY1gW
function name:  go
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ECHO                                                     'Now+I%27m+flying.%0A'
   21     1      > RETURN                                                   null

End of function go

End of class GoByFlying.

Class GoByFlyingFast:
Function go:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY1gW
function name:  go
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ECHO                                                     'Now+I%27m+flying+fast%0A'
   29     1      > RETURN                                                   null

End of function go

End of class GoByFlyingFast.

Class Vehicle:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY1gW
function name:  __construct
number of ops:  4
compiled vars:  !0 = $goType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV_INIT                                        !0      null
   37     1        ASSIGN_OBJ                                               'goAlgorithm'
          2        OP_DATA                                                  !0
   38     3      > RETURN                                                   null

End of function __construct

Function setmodeoftransportation:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY1gW
function name:  setModeOfTransportation
number of ops:  4
compiled vars:  !0 = $goType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        ASSIGN_OBJ                                               'goAlgorithm'
          2        OP_DATA                                                  !0
   43     3      > RETURN                                                   null

End of function setmodeoftransportation

Function drive:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY1gW
function name:  drive
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      'goAlgorithm'
          1        INIT_METHOD_CALL                                         ~0, 'go'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   48     4*     > RETURN                                                   null

End of function drive

End of class Vehicle.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.2 ms | 1394 KiB | 13 Q