3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Example { public $length, $height, $width, $weight; public function __construct($length, $height, $width, $weight) { $this->length = $length; $this->height = $height; $this->width = $width; $this->weight = $weight; } public function get_price() { return 1.23; } } $sample_data = [ 42 => ['quantity' => 2, 'data' => new Example(42, 42, 42, 42)], 69 => ['quantity' => 1, 'data' => new Example(69, 69, 69, 69)], ]; $i = 0; $totalweight = 0; $totalprice = 0; foreach ( $sample_data as $item_id => $values ) { $_product = $values['data']; $q = 1; while ( $values['quantity'] >= $q ) { $products[ $i ]->length = $_product->length; $products[ $i ]->height = $_product->height; $products[ $i ]->width = $_product->width; $products[ $i ]->weight = $_product->weight; $totalweight += $_product->weight; $totalprice += $_product->get_price(); $q++; $i++; } } var_dump($products);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 56
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 56
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 29
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 29
Branch analysis from position: 55
Branch analysis from position: 29
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
filename:       /in/1Imu2
function name:  (null)
number of ops:  61
compiled vars:  !0 = $sample_data, !1 = $i, !2 = $totalweight, !3 = $totalprice, !4 = $values, !5 = $item_id, !6 = $_product, !7 = $q, !8 = $products
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_ARRAY                                       ~9      2, 'quantity'
          1        NEW                                              $10     'Example'
          2        SEND_VAL_EX                                              42
          3        SEND_VAL_EX                                              42
          4        SEND_VAL_EX                                              42
          5        SEND_VAL_EX                                              42
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~9      $10, 'data'
          8        INIT_ARRAY                                       ~12     ~9, 42
   20     9        INIT_ARRAY                                       ~13     1, 'quantity'
         10        NEW                                              $14     'Example'
         11        SEND_VAL_EX                                              69
         12        SEND_VAL_EX                                              69
         13        SEND_VAL_EX                                              69
         14        SEND_VAL_EX                                              69
         15        DO_FCALL                                      0          
         16        ADD_ARRAY_ELEMENT                                ~13     $14, 'data'
         17        ADD_ARRAY_ELEMENT                                ~12     ~13, 69
   18    18        ASSIGN                                                   !0, ~12
   23    19        ASSIGN                                                   !1, 0
   24    20        ASSIGN                                                   !2, 0
   25    21        ASSIGN                                                   !3, 0
   27    22      > FE_RESET_R                                       $20     !0, ->56
         23    > > FE_FETCH_R                                       ~21     $20, !4, ->56
         24    >   ASSIGN                                                   !5, ~21
   28    25        FETCH_DIM_R                                      ~23     !4, 'data'
         26        ASSIGN                                                   !6, ~23
   29    27        ASSIGN                                                   !7, 1
   30    28      > JMP                                                      ->52
   31    29    >   FETCH_OBJ_R                                      ~28     !6, 'length'
         30        FETCH_DIM_W                                      $26     !8, !1
         31        ASSIGN_OBJ                                               $26, 'length'
         32        OP_DATA                                                  ~28
   32    33        FETCH_OBJ_R                                      ~31     !6, 'height'
         34        FETCH_DIM_W                                      $29     !8, !1
         35        ASSIGN_OBJ                                               $29, 'height'
         36        OP_DATA                                                  ~31
   33    37        FETCH_OBJ_R                                      ~34     !6, 'width'
         38        FETCH_DIM_W                                      $32     !8, !1
         39        ASSIGN_OBJ                                               $32, 'width'
         40        OP_DATA                                                  ~34
   34    41        FETCH_OBJ_R                                      ~37     !6, 'weight'
         42        FETCH_DIM_W                                      $35     !8, !1
         43        ASSIGN_OBJ                                               $35, 'weight'
         44        OP_DATA                                                  ~37
   35    45        FETCH_OBJ_R                                      ~38     !6, 'weight'
         46        ASSIGN_OP                                     1          !2, ~38
   36    47        INIT_METHOD_CALL                                         !6, 'get_price'
         48        DO_FCALL                                      0  $40     
         49        ASSIGN_OP                                     1          !3, $40
   37    50        PRE_INC                                                  !7
   38    51        PRE_INC                                                  !1
   30    52    >   FETCH_DIM_R                                      ~44     !4, 'quantity'
         53        IS_SMALLER_OR_EQUAL                                      !7, ~44
         54      > JMPNZ                                                    ~45, ->29
   27    55    > > JMP                                                      ->23
         56    >   FE_FREE                                                  $20
   42    57        INIT_FCALL                                               'var_dump'
         58        SEND_VAR                                                 !8
         59        DO_ICALL                                                 
         60      > RETURN                                                   1

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

End of function __construct

Function get_price:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1Imu2
function name:  get_price
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E > > RETURN                                                   1.23
   15     1*     > RETURN                                                   null

End of function get_price

End of class Example.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.62 ms | 1009 KiB | 14 Q