3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Shipping { private $company; function __construct(){ $this->company = ""; } function setStrategy($company){ $this->company = $company; } function calculate (Package $package){ return $this->company->calculate($package); } } interface Company { public function calculate(); } class UPS implements Company{ public function calculate($package){ return 45 * $package->weight; } } class USPS implements Company{ public function calculate(Package $package){ return 30 * $package->weight; } } class FedEx implements Company { public function calculate(Package $package){ return 60 * $package->weight; } } class Package { public $weight; function __construct($weight){ $this->weight = $weight; } } $package = new Package(30); $shipping = new Shipping(); $shiping->setStrategy(new UPS()); echo $shipping->calculate($package);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  (null)
number of ops:  20
compiled vars:  !0 = $package, !1 = $shipping, !2 = $shiping
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   DECLARE_CLASS                                            'ups'
   33     1        DECLARE_CLASS                                            'usps'
   40     2        DECLARE_CLASS                                            'fedex'
   56     3        NEW                                              $3      'Package'
          4        SEND_VAL_EX                                              30
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $3
   57     7        NEW                                              $6      'Shipping'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $6
   58    10        INIT_METHOD_CALL                                         !2, 'setStrategy'
         11        NEW                                              $9      'UPS'
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $9
         14        DO_FCALL                                      0          
   59    15        INIT_METHOD_CALL                                         !1, 'calculate'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $12     
         18        ECHO                                                     $12
         19      > RETURN                                                   1

Class Shipping:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  __construct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN_OBJ                                               'company'
          1        OP_DATA                                                  ''
    9     2      > RETURN                                                   null

End of function __construct

Function setstrategy:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  setStrategy
number of ops:  4
compiled vars:  !0 = $company
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'company'
          2        OP_DATA                                                  !0
   15     3      > RETURN                                                   null

End of function setstrategy

Function calculate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  calculate
number of ops:  7
compiled vars:  !0 = $package
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        FETCH_OBJ_R                                      ~1      'company'
          2        INIT_METHOD_CALL                                         ~1, 'calculate'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   20     6*     > RETURN                                                   null

End of function calculate

End of class Shipping.

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

End of function calculate

End of class Company.

Class UPS:
Function calculate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  calculate
number of ops:  5
compiled vars:  !0 = $package
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        FETCH_OBJ_R                                      ~1      !0, 'weight'
          2        MUL                                              ~2      ~1, 45
          3      > RETURN                                                   ~2
   30     4*     > RETURN                                                   null

End of function calculate

End of class UPS.

Class USPS:
Function calculate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  calculate
number of ops:  5
compiled vars:  !0 = $package
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1        FETCH_OBJ_R                                      ~1      !0, 'weight'
          2        MUL                                              ~2      ~1, 30
          3      > RETURN                                                   ~2
   38     4*     > RETURN                                                   null

End of function calculate

End of class USPS.

Class FedEx:
Function calculate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  calculate
number of ops:  5
compiled vars:  !0 = $package
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     1        FETCH_OBJ_R                                      ~1      !0, 'weight'
          2        MUL                                              ~2      ~1, 60
          3      > RETURN                                                   ~2
   45     4*     > RETURN                                                   null

End of function calculate

End of class FedEx.

Class Package:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cHAPU
function name:  __construct
number of ops:  4
compiled vars:  !0 = $weight
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   52     1        ASSIGN_OBJ                                               'weight'
          2        OP_DATA                                                  !0
   53     3      > RETURN                                                   null

End of function __construct

End of class Package.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.21 ms | 1403 KiB | 13 Q