3v4l.org

run code in 500+ 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)], ]; $products = []; $i = 0; $totalweight = 0; $totalprice = 0; foreach ( $sample_data as $item_id => $values ) { $_product = $values['data']; $q = 1; while ( $values['quantity'] >= $q ) { $products[ $i ] = new stdClass; $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 = 24, Position 2 = 61
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 61
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 30
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 30
Branch analysis from position: 60
Branch analysis from position: 30
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
filename:       /in/8Fgpg
function name:  (null)
number of ops:  66
compiled vars:  !0 = $sample_data, !1 = $products, !2 = $i, !3 = $totalweight, !4 = $totalprice, !5 = $values, !6 = $item_id, !7 = $_product, !8 = $q
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, <array>
   24    20        ASSIGN                                                       !2, 0
   25    21        ASSIGN                                                       !3, 0
   26    22        ASSIGN                                                       !4, 0
   28    23      > FE_RESET_R                                           $21     !0, ->61
         24    > > FE_FETCH_R                                           ~22     $21, !5, ->61
         25    >   ASSIGN                                                       !6, ~22
   29    26        FETCH_DIM_R                                          ~24     !5, 'data'
         27        ASSIGN                                                       !7, ~24
   30    28        ASSIGN                                                       !8, 1
   31    29      > JMP                                                          ->57
   32    30    >   NEW                                                  $28     'stdClass'
         31        DO_FCALL                                          0          
         32        ASSIGN_DIM                                                   !1, !2
         33        OP_DATA                                                      $28
   33    34        FETCH_OBJ_R                                          ~32     !7, 'length'
         35        FETCH_DIM_W                                          $30     !1, !2
         36        ASSIGN_OBJ                                                   $30, 'length'
         37        OP_DATA                                                      ~32
   34    38        FETCH_OBJ_R                                          ~35     !7, 'height'
         39        FETCH_DIM_W                                          $33     !1, !2
         40        ASSIGN_OBJ                                                   $33, 'height'
         41        OP_DATA                                                      ~35
   35    42        FETCH_OBJ_R                                          ~38     !7, 'width'
         43        FETCH_DIM_W                                          $36     !1, !2
         44        ASSIGN_OBJ                                                   $36, 'width'
         45        OP_DATA                                                      ~38
   36    46        FETCH_OBJ_R                                          ~41     !7, 'weight'
         47        FETCH_DIM_W                                          $39     !1, !2
         48        ASSIGN_OBJ                                                   $39, 'weight'
         49        OP_DATA                                                      ~41
   37    50        FETCH_OBJ_R                                          ~42     !7, 'weight'
         51        ASSIGN_OP                                         1          !3, ~42
   38    52        INIT_METHOD_CALL                                             !7, 'get_price'
         53        DO_FCALL                                          0  $44     
         54        ASSIGN_OP                                         1          !4, $44
   39    55        PRE_INC                                                      !8
   40    56        PRE_INC                                                      !2
   31    57    >   FETCH_DIM_R                                          ~48     !5, 'quantity'
         58        IS_SMALLER_OR_EQUAL                                          !8, ~48
         59      > JMPNZ                                                        ~49, ->30
   28    60    > > JMP                                                          ->24
         61    >   FE_FREE                                                      $21
   44    62        INIT_FCALL                                                   'var_dump'
         63        SEND_VAR                                                     !1
         64        DO_ICALL                                                     
         65      > RETURN                                                       1

Class Example:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Fgpg
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/8Fgpg
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.5.0


preferences:
163.78 ms | 3562 KiB | 14 Q