3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataStructure { private $data = []; public function __construct(string $data) { foreach (explode('|', $data) as $item_quantity) { list($quantity, $item) = explode(':', $item_quantity); $this->data[$item] = (int)$quantity; } } public function getItemQuantity(int $item): ?int { return $this->data[$item] ?? null; } public function setItemQuantity(int $item, int $quantity) { $this->data[$item] = $quantity; } public function __toString(): string { return implode('|', array_map(function ($item) { return $this->data[$item] . ':' . $item; }, array_keys($this->data))); } } $data = new DataStructure('3:1|8:2|5:3|4:4'); $data->setItemQuantity(4, '12'); var_dump($data->getItemQuantity(4)); var_dump($data->getItemQuantity(2)); var_dump($data->getItemQuantity(12));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pqRQh
function name:  (null)
number of ops:  28
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'datastructure'
   32     1        NEW                                              $1      'DataStructure'
          2        SEND_VAL_EX                                              '3%3A1%7C8%3A2%7C5%3A3%7C4%3A4'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   33     5        INIT_METHOD_CALL                                         !0, 'setItemQuantity'
          6        SEND_VAL_EX                                              4
          7        SEND_VAL_EX                                              '12'
          8        DO_FCALL                                      0          
   35     9        INIT_FCALL                                               'var_dump'
         10        INIT_METHOD_CALL                                         !0, 'getItemQuantity'
         11        SEND_VAL_EX                                              4
         12        DO_FCALL                                      0  $5      
         13        SEND_VAR                                                 $5
         14        DO_ICALL                                                 
   36    15        INIT_FCALL                                               'var_dump'
         16        INIT_METHOD_CALL                                         !0, 'getItemQuantity'
         17        SEND_VAL_EX                                              2
         18        DO_FCALL                                      0  $7      
         19        SEND_VAR                                                 $7
         20        DO_ICALL                                                 
   37    21        INIT_FCALL                                               'var_dump'
         22        INIT_METHOD_CALL                                         !0, 'getItemQuantity'
         23        SEND_VAL_EX                                              12
         24        DO_FCALL                                      0  $9      
         25        SEND_VAR                                                 $9
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Class DataStructure:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 21
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/pqRQh
function name:  __construct
number of ops:  23
compiled vars:  !0 = $data, !1 = $item_quantity, !2 = $quantity, !3 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%7C'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5      > FE_RESET_R                                       $5      $4, ->21
          6    > > FE_FETCH_R                                               $5, !1, ->21
    9     7    >   INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%3A'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $6      
         11        FETCH_LIST_R                                     $7      $6, 0
         12        ASSIGN                                                   !2, $7
         13        FETCH_LIST_R                                     $9      $6, 1
         14        ASSIGN                                                   !3, $9
         15        FREE                                                     $6
   10    16        CAST                                          4  ~13     !2
         17        FETCH_OBJ_W                                      $11     'data'
         18        ASSIGN_DIM                                               $11, !3
         19        OP_DATA                                                  ~13
    8    20      > JMP                                                      ->6
         21    >   FE_FREE                                                  $5
   12    22      > RETURN                                                   null

End of function __construct

Function getitemquantity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pqRQh
function name:  getItemQuantity
number of ops:  9
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        FETCH_OBJ_IS                                     ~1      'data'
          2        FETCH_DIM_IS                                     ~2      ~1, !0
          3        COALESCE                                         ~3      ~2
          4        QM_ASSIGN                                        ~3      null
          5        VERIFY_RETURN_TYPE                                       ~3
          6      > RETURN                                                   ~3
   17     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function getitemquantity

Function setitemquantity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pqRQh
function name:  setItemQuantity
number of ops:  6
compiled vars:  !0 = $item, !1 = $quantity
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        FETCH_OBJ_W                                      $2      'data'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   22     5      > RETURN                                                   null

End of function setitemquantity

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pqRQh
function name:  __toString
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'implode'
          1        SEND_VAL                                                 '%7C'
          2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                          ~0      [0]
   28     4        SEND_VAL                                                 ~0
          5        INIT_FCALL                                               'array_keys'
          6        FETCH_OBJ_R                                      ~1      'data'
          7        SEND_VAL                                                 ~1
          8        DO_ICALL                                         $2      
          9        SEND_VAR                                                 $2
   26    10        DO_ICALL                                         $3      
   28    11        SEND_VAR                                                 $3
   26    12        DO_ICALL                                         $4      
   28    13        VERIFY_RETURN_TYPE                                       $4
         14      > RETURN                                                   $4
   29    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pqRQh
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        FETCH_THIS                                       $1      
          2        FETCH_OBJ_R                                      ~2      $1, 'data'
          3        FETCH_DIM_R                                      ~3      ~2, !0
          4        CONCAT                                           ~4      ~3, '%3A'
          5        CONCAT                                           ~5      ~4, !0
          6      > RETURN                                                   ~5
   28     7*     > RETURN                                                   null

End of Dynamic Function 0

End of function __tostring

End of class DataStructure.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.19 ms | 1011 KiB | 18 Q