3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Cart{ private $cart_items = array(); private $number_of_cart_items; public function add_to_cart($item, $quantity = 1){ if(!isset($item) || !isset($item->ItemID)){ throw new Exception("Error adding item to cart"); } if(!array_key_exists($item->ItemID,$this->cart_items)){ $this->cart_items[$item->ItemID] = array("Item"=>$item,"Quantity"=>$quantity); }else{ $this->cart_items[$item->ItemID]["Quantity"] += $quantity; } $this->number_of_cart_items+=$quantity; return $this->cart_items; } } $itemArray = array( "ItemID" => 11, "ItemName" => "Kids check T-Shirt", "ShortDescription" => "A kids check T-Shirt", "LongDescription"=>"A kids check T-shirt perfect for formal occasions!", "ItemPrice" => 33.59, "ImagePath" => "kozzi-26129586-1591x2387.jpg", "QuantityAvailable" => 100, "ItemSupplier_SupplierID" => 1 ); $quantity = 1; $item = (object)$itemArray ; $cart = new Cart(); $add_to_cart = $cart->add_to_cart($item,$quantity); print_r($add_to_cart); var_dump($add_to_cart);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N96Vc
function name:  (null)
number of ops:  19
compiled vars:  !0 = $itemArray, !1 = $quantity, !2 = $item, !3 = $cart, !4 = $add_to_cart
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   31     1        ASSIGN                                                   !1, 1
   32     2        CAST                                          8  ~7      !0
          3        ASSIGN                                                   !2, ~7
   35     4        NEW                                              $9      'Cart'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !3, $9
   36     7        INIT_METHOD_CALL                                         !3, 'add_to_cart'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $12     
         11        ASSIGN                                                   !4, $12
   39    12        INIT_FCALL                                               'print_r'
         13        SEND_VAR                                                 !4
         14        DO_ICALL                                                 
   40    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Class Cart:
Function add_to_cart:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/N96Vc
function name:  add_to_cart
number of ops:  35
compiled vars:  !0 = $item, !1 = $quantity
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
    7     2        ISSET_ISEMPTY_CV                                 ~2      !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPNZ_EX                                         ~3      ~3, ->8
          5    >   ISSET_ISEMPTY_PROP_OBJ                           ~4      !0, 'ItemID'
          6        BOOL_NOT                                         ~5      ~4
          7        BOOL                                             ~3      ~5
          8    > > JMPZ                                                     ~3, ->13
    8     9    >   NEW                                              $6      'Exception'
         10        SEND_VAL_EX                                              'Error+adding+item+to+cart'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $6
   10    13    >   FETCH_OBJ_R                                      ~8      !0, 'ItemID'
         14        FETCH_OBJ_R                                      ~9      'cart_items'
         15        ARRAY_KEY_EXISTS                                 ~10     ~8, ~9
         16        BOOL_NOT                                         ~11     ~10
         17      > JMPZ                                                     ~11, ->25
   11    18    >   FETCH_OBJ_R                                      ~13     !0, 'ItemID'
         19        INIT_ARRAY                                       ~15     !0, 'Item'
         20        ADD_ARRAY_ELEMENT                                ~15     !1, 'Quantity'
         21        FETCH_OBJ_W                                      $12     'cart_items'
         22        ASSIGN_DIM                                               $12, ~13
         23        OP_DATA                                                  ~15
         24      > JMP                                                      ->30
   13    25    >   FETCH_OBJ_R                                      ~17     !0, 'ItemID'
         26        FETCH_OBJ_RW                                     $16     'cart_items'
         27        FETCH_DIM_RW                                     $18     $16, ~17
         28        ASSIGN_DIM_OP                +=               1          $18, 'Quantity'
         29        OP_DATA                                                  !1
   15    30    >   ASSIGN_OBJ_OP                                 1          'number_of_cart_items'
         31        OP_DATA                                                  !1
   16    32        FETCH_OBJ_R                                      ~21     'cart_items'
         33      > RETURN                                                   ~21
   17    34*     > RETURN                                                   null

End of function add_to_cart

End of class Cart.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.73 ms | 1405 KiB | 17 Q