3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CartEntry { //changing to private private $Price; private $Quantity; public function __construct($Price, $Quantity) { $this->Price = $Price; $this->Quantity = $Quantity; } public function ReturnPrice() { return $this->Price; } public function ReturnQuantity() { return $this->Quantity; } }// end class class CartContents { //Changed to private private $items = array(); public function __construct($items) { $this->items = $items; } public function ReturnItems() { return $this->items; } } // end class class Order { private $cart; private $salesTax; function __construct( float $salesTax, Array $items){ $this->salesTax = $salesTax; $this->items = $items; } function OrderTotal() { $cartTotal = 0; for ($i=0, $max=count($this->items); $i < $max; $i++) { $cartTotal += $this->items[$i]->ReturnPrice() * $this->items[$i]->ReturnQuantity(); } $cartTotal += $cartTotal * $this->salesTax; return $cartTotal; } } $entry1 = new CartEntry(1.2, 120); $entry2 = new CartEntry(2.2,200); $mycart = new CartContents([$entry1,$entry2]); $items = $mycart->ReturnItems(); $mytax = 0.2; //Items variable can be changed with mycart $myorder = new Order($mytax,$items); echo $myorder->OrderTotal();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Xbnls
function name:  (null)
number of ops:  29
compiled vars:  !0 = $entry1, !1 = $entry2, !2 = $mycart, !3 = $items, !4 = $mytax, !5 = $myorder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   NEW                                              $6      'CartEntry'
          1        SEND_VAL_EX                                              1.2
          2        SEND_VAL_EX                                              120
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $6
   60     5        NEW                                              $9      'CartEntry'
          6        SEND_VAL_EX                                              2.2
          7        SEND_VAL_EX                                              200
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $9
   62    10        NEW                                              $12     'CartContents'
         11        INIT_ARRAY                                       ~13     !0
         12        ADD_ARRAY_ELEMENT                                ~13     !1
         13        SEND_VAL_EX                                              ~13
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !2, $12
   63    16        INIT_METHOD_CALL                                         !2, 'ReturnItems'
         17        DO_FCALL                                      0  $16     
         18        ASSIGN                                                   !3, $16
   64    19        ASSIGN                                                   !4, 0.2
   67    20        NEW                                              $19     'Order'
         21        SEND_VAR_EX                                              !4
         22        SEND_VAR_EX                                              !3
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !5, $19
   68    25        INIT_METHOD_CALL                                         !5, 'OrderTotal'
         26        DO_FCALL                                      0  $22     
         27        ECHO                                                     $22
         28      > RETURN                                                   1

Class CartEntry:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Xbnls
function name:  __construct
number of ops:  7
compiled vars:  !0 = $Price, !1 = $Quantity
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN_OBJ                                               'Price'
          3        OP_DATA                                                  !0
   11     4        ASSIGN_OBJ                                               'Quantity'
          5        OP_DATA                                                  !1
   12     6      > RETURN                                                   null

End of function __construct

Function returnprice:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Xbnls
function name:  ReturnPrice
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                      ~0      'Price'
          1      > RETURN                                                   ~0
   16     2*     > RETURN                                                   null

End of function returnprice

Function returnquantity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Xbnls
function name:  ReturnQuantity
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   FETCH_OBJ_R                                      ~0      'Quantity'
          1      > RETURN                                                   ~0
   19     2*     > RETURN                                                   null

End of function returnquantity

End of class CartEntry.

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

End of function __construct

Function returnitems:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Xbnls
function name:  ReturnItems
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                      ~0      'items'
          1      > RETURN                                                   ~0
   32     2*     > RETURN                                                   null

End of function returnitems

End of class CartContents.

Class Order:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Xbnls
function name:  __construct
number of ops:  7
compiled vars:  !0 = $salesTax, !1 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   43     2        ASSIGN_OBJ                                               'salesTax'
          3        OP_DATA                                                  !0
   44     4        ASSIGN_OBJ                                               'items'
          5        OP_DATA                                                  !1
   45     6      > RETURN                                                   null

End of function __construct

Function ordertotal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 6
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 6
Branch analysis from position: 19
Branch analysis from position: 6
filename:       /in/Xbnls
function name:  OrderTotal
number of ops:  24
compiled vars:  !0 = $cartTotal, !1 = $i, !2 = $max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, 0
   51     1        ASSIGN                                                   !1, 0
          2        FETCH_OBJ_R                                      ~5      'items'
          3        COUNT                                            ~6      ~5
          4        ASSIGN                                                   !2, ~6
          5      > JMP                                                      ->17
   52     6    >   FETCH_OBJ_R                                      ~8      'items'
          7        FETCH_DIM_R                                      ~9      ~8, !1
          8        INIT_METHOD_CALL                                         ~9, 'ReturnPrice'
          9        DO_FCALL                                      0  $10     
         10        FETCH_OBJ_R                                      ~11     'items'
         11        FETCH_DIM_R                                      ~12     ~11, !1
         12        INIT_METHOD_CALL                                         ~12, 'ReturnQuantity'
         13        DO_FCALL                                      0  $13     
         14        MUL                                              ~14     $10, $13
         15        ASSIGN_OP                                     1          !0, ~14
   51    16        PRE_INC                                                  !1
         17    >   IS_SMALLER                                               !1, !2
         18      > JMPNZ                                                    ~17, ->6
   54    19    >   FETCH_OBJ_R                                      ~18     'salesTax'
         20        MUL                                              ~19     !0, ~18
         21        ASSIGN_OP                                     1          !0, ~19
   55    22      > RETURN                                                   !0
   56    23*     > RETURN                                                   null

End of function ordertotal

End of class Order.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.47 ms | 1414 KiB | 13 Q