3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Cart { const PRICE_BUTTER = 1.00; const PRICE_MILK = 3.00; const PRICE_EGGS = 6.95; protected $products = array(); public function add($product, $quantity) { $this->products[$product] = $quantity; } public function getQuantity($product) { return isset($this->products[$product]) ? $this->products[$product] : FALSE; } public function getTotal($tax) { $total = 0.00; $callback = function ($quantity, $product) use ($tax, &$total) { $pricePerItem = constant(__CLASS__ . "::PRICE_" . strtoupper($product)); $total += ($pricePerItem * $quantity) * ($tax + 1.0); }; array_walk($this->products, $callback); return round($total, 2); } } $my_cart = new Cart; // Add some items to the cart $my_cart->add('butter', 1); $my_cart->add('milk', 3); // Print the total with a 5% sales tax. print $my_cart->getTotal(0.05) . "\n"; // The result is 54.29 ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oXVC5
function name:  (null)
number of ops:  17
compiled vars:  !0 = $my_cart
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   NEW                                              $1      'Cart'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   42     3        INIT_METHOD_CALL                                         !0, 'add'
          4        SEND_VAL_EX                                              'butter'
          5        SEND_VAL_EX                                              1
          6        DO_FCALL                                      0          
   43     7        INIT_METHOD_CALL                                         !0, 'add'
          8        SEND_VAL_EX                                              'milk'
          9        SEND_VAL_EX                                              3
         10        DO_FCALL                                      0          
   47    11        INIT_METHOD_CALL                                         !0, 'getTotal'
         12        SEND_VAL_EX                                              0.05
         13        DO_FCALL                                      0  $6      
         14        CONCAT                                           ~7      $6, '%0A'
         15        ECHO                                                     ~7
   49    16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FoXVC5%3A27%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oXVC5
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $quantity, !1 = $product, !2 = $tax, !3 = $total, !4 = $pricePerItem
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   29     4        INIT_FCALL                                               'constant'
   30     5        INIT_FCALL                                               'strtoupper'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $5      
          8        CONCAT                                           ~6      'Cart%3A%3APRICE_', $5
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                         $7      
   29    11        ASSIGN                                                   !4, $7
   31    12        MUL                                              ~9      !4, !0
         13        ADD                                              ~10     !2, 1
         14        MUL                                              ~11     ~9, ~10
         15        ASSIGN_OP                                     1          !3, ~11
   32    16      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FoXVC5%3A27%240

Class Cart:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oXVC5
function name:  add
number of ops:  6
compiled vars:  !0 = $product, !1 = $quantity
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        FETCH_OBJ_W                                      $2      'products'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   14     5      > RETURN                                                   null

End of function add

Function getquantity:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oXVC5
function name:  getQuantity
number of ops:  11
compiled vars:  !0 = $product
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        FETCH_OBJ_IS                                     ~1      'products'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->8
          4    >   FETCH_OBJ_R                                      ~3      'products'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6        QM_ASSIGN                                        ~5      ~4
          7      > JMP                                                      ->9
   19     8    >   QM_ASSIGN                                        ~5      <false>
          9    > > RETURN                                                   ~5
   20    10*     > RETURN                                                   null

End of function getquantity

Function gettotal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oXVC5
function name:  getTotal
number of ops:  17
compiled vars:  !0 = $tax, !1 = $total, !2 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        ASSIGN                                                   !1, 0
   27     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FoXVC5%3A27%240'
          3        BIND_LEXICAL                                             ~4, !0
          4        BIND_LEXICAL                                             ~4, !1
   26     5        ASSIGN                                                   !2, ~4
   34     6        INIT_FCALL                                               'array_walk'
          7        FETCH_OBJ_W                                      $6      'products'
          8        SEND_REF                                                 $6
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                                 
   35    11        INIT_FCALL                                               'round'
         12        SEND_VAR                                                 !1
         13        SEND_VAL                                                 2
         14        DO_ICALL                                         $8      
         15      > RETURN                                                   $8
   36    16*     > RETURN                                                   null

End of function gettotal

End of class Cart.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.45 ms | 1400 KiB | 21 Q