3v4l.org

run code in 300+ PHP versions simultaneously
<?php //EXAMPLE, PSEUDO CODE class Cart{ protected $items = [];//array of id => [stuff] public function __construct(){ $this->read(); } //$attributes - IDK, maybe quantity or ... something... public function add(int $id, array $attributes = []){ if(isset($this->items [$id])){ //@todo - do smth about it... } $this->items [$id][] = $attributes; return $this; } public function read(){ //might change this later, to db and or serialization $this->items = json_decode((isset($_SESSION['cart']))); return $this; } public function write(){ //might change this later, to db and or serialization $_SESSION['cart'] = json_encode($this->items); return $this; } public function getItems(){ return $this->items; } } /// //thing is you don't care HERE about internal implementaion. Which can be changed later. $cart = new Cart(); $cart->add(17,['quantity' => 12]); $cart->add(42,['quantity' => 99])->write(); var_dump($cart->getItems());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8A7Pv
function name:  (null)
number of ops:  19
compiled vars:  !0 = $cart
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   NEW                                              $1      'Cart'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   41     3        INIT_METHOD_CALL                                         !0, 'add'
          4        SEND_VAL_EX                                              17
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
   42     7        INIT_METHOD_CALL                                         !0, 'add'
          8        SEND_VAL_EX                                              42
          9        SEND_VAL_EX                                              <array>
         10        DO_FCALL                                      0  $5      
         11        INIT_METHOD_CALL                                         $5, 'write'
         12        DO_FCALL                                      0          
   43    13        INIT_FCALL                                               'var_dump'
         14        INIT_METHOD_CALL                                         !0, 'getItems'
         15        DO_FCALL                                      0  $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

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

End of function __construct

Function add:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 5
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/8A7Pv
function name:  add
number of ops:  12
compiled vars:  !0 = $id, !1 = $attributes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   14     2        FETCH_OBJ_IS                                     ~2      'items'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~2, !0
          4      > JMPZ                                                     ~3, ->5
   17     5    >   FETCH_OBJ_W                                      $4      'items'
          6        FETCH_DIM_W                                      $5      $4, !0
          7        ASSIGN_DIM                                               $5
          8        OP_DATA                                                  !1
   18     9        FETCH_THIS                                       ~7      
         10      > RETURN                                                   ~7
   19    11*     > RETURN                                                   null

End of function add

Function read:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8A7Pv
function name:  read
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'json_decode'
          1        FETCH_IS                                         ~1      '_SESSION'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, 'cart'
          3        SEND_VAL                                                 ~2
          4        DO_ICALL                                         $3      
          5        ASSIGN_OBJ                                               'items'
          6        OP_DATA                                                  $3
   24     7        FETCH_THIS                                       ~4      
          8      > RETURN                                                   ~4
   25     9*     > RETURN                                                   null

End of function read

Function write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8A7Pv
function name:  write
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'json_encode'
          1        FETCH_OBJ_R                                      ~2      'items'
          2        SEND_VAL                                                 ~2
          3        DO_ICALL                                         $3      
          4        FETCH_W                      global              $0      '_SESSION'
          5        ASSIGN_DIM                                               $0, 'cart'
          6        OP_DATA                                                  $3
   30     7        FETCH_THIS                                       ~4      
          8      > RETURN                                                   ~4
   31     9*     > RETURN                                                   null

End of function write

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

End of function getitems

End of class Cart.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.38 ms | 1400 KiB | 19 Q