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."); } } class GoByFlying implements GoAlgorithm { public function go() { echo("Now I'm flying."); } } class GoByFlyingFast implements GoAlgorithm { public function go() { echo("Now I'm flying fast"); } } abstract class Vehicle { private $goAlgorithm; public static function setGoAlgorithm($goAlgorithm = TRUE) { return $goAlgorithm = 'GoAlgorithm'; } } class StreetRacer extends Vehicle { public function StreetRacer($goAlgorithm=TRUE) { Vehicle::setGoAlgorithm($str=new GoByDrivingAlgorithm(), $str->go()); } } class FormulaOne extends Vehicle { public function FormulaOne() { Vehicle::setGoAlgorithm($for=new GoByDrivingAlgorithm(), $for->go()); } } class Helicopter extends Vehicle { public function Helicopter() { Vehicle::setGoAlgorithm($hel=new GoByFlying(), $hel->go()); } } class Jet extends Vehicle { public function Jet() { Vehicle::setGoAlgorithm($jet=new GoByFlyingFast(), $jet->go()); } } class StartTheRace { public static function main() { $streetRacer = new StreetRacer(); $formulaone = new FormulaOne(); $helicopter = new Helicopter(); $jets = new Jet(); } } //StartTheRace::main(); class RealJet //dodatak na klase bez extends ali ako idu na druge stranice onda treba autoload require_one {//potreba ka drugog lokaciji app, mogla bi da bude i sa require interface.php public static function main() { //samo poziv objekta koji poziva njegovu funkciju $jet = new StreetRacer(); $jet = new Helicopter(); $jet = new StreetRacer(); } } RealJet::main();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'gobydrivingalgorithm'
   16     1        DECLARE_CLASS                                            'gobyflying'
   25     2        DECLARE_CLASS                                            'gobyflyingfast'
  103     3        INIT_STATIC_METHOD_CALL                                  'RealJet', 'main'
          4        DO_FCALL                                      0          
          5      > RETURN                                                   1

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

End of function go

End of class GoByFlyingFast.

Class Vehicle:
Function setgoalgorithm:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  setGoAlgorithm
number of ops:  4
compiled vars:  !0 = $goAlgorithm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV_INIT                                        !0      <true>
   40     1        ASSIGN                                           ~1      !0, 'GoAlgorithm'
          2      > RETURN                                                   ~1
   41     3*     > RETURN                                                   null

End of function setgoalgorithm

End of class Vehicle.

Class StreetRacer:
Function streetracer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  StreetRacer
number of ops:  11
compiled vars:  !0 = $goAlgorithm, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV_INIT                                        !0      <true>
   48     1        INIT_STATIC_METHOD_CALL                                  'Vehicle', 'setGoAlgorithm'
          2        NEW                                              $2      'GoByDrivingAlgorithm'
          3        DO_FCALL                                      0          
          4        ASSIGN                                           ~4      !1, $2
          5        SEND_VAL                                                 ~4
          6        INIT_METHOD_CALL                                         !1, 'go'
          7        DO_FCALL                                      0  $5      
          8        SEND_VAR                                                 $5
          9        DO_FCALL                                      0          
   49    10      > RETURN                                                   null

End of function streetracer

Function setgoalgorithm:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  setGoAlgorithm
number of ops:  4
compiled vars:  !0 = $goAlgorithm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV_INIT                                        !0      <true>
   40     1        ASSIGN                                           ~1      !0, 'GoAlgorithm'
          2      > RETURN                                                   ~1
   41     3*     > RETURN                                                   null

End of function setgoalgorithm

End of class StreetRacer.

Class FormulaOne:
Function formulaone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  FormulaOne
number of ops:  10
compiled vars:  !0 = $for
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_STATIC_METHOD_CALL                                  'Vehicle', 'setGoAlgorithm'
          1        NEW                                              $1      'GoByDrivingAlgorithm'
          2        DO_FCALL                                      0          
          3        ASSIGN                                           ~3      !0, $1
          4        SEND_VAL                                                 ~3
          5        INIT_METHOD_CALL                                         !0, 'go'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_FCALL                                      0          
   57     9      > RETURN                                                   null

End of function formulaone

Function setgoalgorithm:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  setGoAlgorithm
number of ops:  4
compiled vars:  !0 = $goAlgorithm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV_INIT                                        !0      <true>
   40     1        ASSIGN                                           ~1      !0, 'GoAlgorithm'
          2      > RETURN                                                   ~1
   41     3*     > RETURN                                                   null

End of function setgoalgorithm

End of class FormulaOne.

Class Helicopter:
Function helicopter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  Helicopter
number of ops:  10
compiled vars:  !0 = $hel
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   INIT_STATIC_METHOD_CALL                                  'Vehicle', 'setGoAlgorithm'
          1        NEW                                              $1      'GoByFlying'
          2        DO_FCALL                                      0          
          3        ASSIGN                                           ~3      !0, $1
          4        SEND_VAL                                                 ~3
          5        INIT_METHOD_CALL                                         !0, 'go'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_FCALL                                      0          
   65     9      > RETURN                                                   null

End of function helicopter

Function setgoalgorithm:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  setGoAlgorithm
number of ops:  4
compiled vars:  !0 = $goAlgorithm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV_INIT                                        !0      <true>
   40     1        ASSIGN                                           ~1      !0, 'GoAlgorithm'
          2      > RETURN                                                   ~1
   41     3*     > RETURN                                                   null

End of function setgoalgorithm

End of class Helicopter.

Class Jet:
Function jet:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  Jet
number of ops:  10
compiled vars:  !0 = $jet
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   INIT_STATIC_METHOD_CALL                                  'Vehicle', 'setGoAlgorithm'
          1        NEW                                              $1      'GoByFlyingFast'
          2        DO_FCALL                                      0          
          3        ASSIGN                                           ~3      !0, $1
          4        SEND_VAL                                                 ~3
          5        INIT_METHOD_CALL                                         !0, 'go'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_FCALL                                      0          
   73     9      > RETURN                                                   null

End of function jet

Function setgoalgorithm:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  setGoAlgorithm
number of ops:  4
compiled vars:  !0 = $goAlgorithm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV_INIT                                        !0      <true>
   40     1        ASSIGN                                           ~1      !0, 'GoAlgorithm'
          2      > RETURN                                                   ~1
   41     3*     > RETURN                                                   null

End of function setgoalgorithm

End of class Jet.

Class StartTheRace:
Function main:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  main
number of ops:  13
compiled vars:  !0 = $streetRacer, !1 = $formulaone, !2 = $helicopter, !3 = $jets
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   NEW                                              $4      'StreetRacer'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   81     3        NEW                                              $7      'FormulaOne'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $7
   82     6        NEW                                              $10     'Helicopter'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $10
   83     9        NEW                                              $13     'Jet'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !3, $13
   84    12      > RETURN                                                   null

End of function main

End of class StartTheRace.

Class RealJet:
Function main:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FAgju
function name:  main
number of ops:  10
compiled vars:  !0 = $jet
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   NEW                                              $1      'StreetRacer'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   96     3        NEW                                              $4      'Helicopter'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $4
   97     6        NEW                                              $7      'StreetRacer'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $7
  100     9      > RETURN                                                   null

End of function main

End of class RealJet.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.57 ms | 1407 KiB | 13 Q