3v4l.org

run code in 300+ PHP versions simultaneously
<?php // create array of objects $arr = [new stdClass, new stdClass, new StdClass]; // assign properties for($i=0, $max=count($arr); $i < $max; $i++) { $arr[$i]->age = 0; $arr[$i]->creature = "squirrel"; } // update age values $arr[0]->age = 10; $arr[1]->age = 25; $arr[2]->age = 30; // recursively sum the ages of the array of objects ... function getTotalYears( $arr, $i, $carry ) { if ($i >= ( count( $arr ) - 1 ) ){ return $carry; } else { $carry += $arr[$i++]->age; getTotalYears( $arr, $i, $carry ); } } // .. and display result $total = getTotalYears( $arr, 0, 0); var_dump($total); echo "\nTotal years of nut foraging experience: $total";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
Branch analysis from position: 14
filename:       /in/PL97h
function name:  (null)
number of ops:  45
compiled vars:  !0 = $arr, !1 = $i, !2 = $max, !3 = $total
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   NEW                                              $4      'stdClass'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~6      $4
          3        NEW                                              $7      'stdClass'
          4        DO_FCALL                                      0          
          5        ADD_ARRAY_ELEMENT                                ~6      $7
          6        NEW                                              $9      'StdClass'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~6      $9
          9        ASSIGN                                                   !0, ~6
    7    10        ASSIGN                                                   !1, 0
         11        COUNT                                            ~13     !0
         12        ASSIGN                                                   !2, ~13
         13      > JMP                                                      ->21
    8    14    >   FETCH_DIM_W                                      $15     !0, !1
         15        ASSIGN_OBJ                                               $15, 'age'
         16        OP_DATA                                                  0
    9    17        FETCH_DIM_W                                      $17     !0, !1
         18        ASSIGN_OBJ                                               $17, 'creature'
         19        OP_DATA                                                  'squirrel'
    7    20        PRE_INC                                                  !1
         21    >   IS_SMALLER                                               !1, !2
         22      > JMPNZ                                                    ~20, ->14
   13    23    >   FETCH_DIM_W                                      $21     !0, 0
         24        ASSIGN_OBJ                                               $21, 'age'
         25        OP_DATA                                                  10
   14    26        FETCH_DIM_W                                      $23     !0, 1
         27        ASSIGN_OBJ                                               $23, 'age'
         28        OP_DATA                                                  25
   15    29        FETCH_DIM_W                                      $25     !0, 2
         30        ASSIGN_OBJ                                               $25, 'age'
         31        OP_DATA                                                  30
   33    32        INIT_FCALL                                               'gettotalyears'
         33        SEND_VAR                                                 !0
         34        SEND_VAL                                                 0
         35        SEND_VAL                                                 0
         36        DO_FCALL                                      0  $27     
         37        ASSIGN                                                   !3, $27
   34    38        INIT_FCALL                                               'var_dump'
         39        SEND_VAR                                                 !3
         40        DO_ICALL                                                 
   35    41        NOP                                                      
         42        FAST_CONCAT                                      ~30     '%0ATotal+years+of+nut+foraging+experience%3A+', !3
         43        ECHO                                                     ~30
         44      > RETURN                                                   1

Function gettotalyears:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PL97h
function name:  getTotalYears
number of ops:  19
compiled vars:  !0 = $arr, !1 = $i, !2 = $carry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   20     3        COUNT                                            ~3      !0
          4        SUB                                              ~4      ~3, 1
          5        IS_SMALLER_OR_EQUAL                                      ~4, !1
          6      > JMPZ                                                     ~5, ->9
   21     7    > > RETURN                                                   !2
          8*       JMP                                                      ->18
   25     9    >   POST_INC                                         ~6      !1
         10        FETCH_DIM_R                                      ~7      !0, ~6
         11        FETCH_OBJ_R                                      ~8      ~7, 'age'
         12        ASSIGN_OP                                     1          !2, ~8
   26    13        INIT_FCALL_BY_NAME                                       'getTotalYears'
         14        SEND_VAR_EX                                              !0
         15        SEND_VAR_EX                                              !1
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0          
   30    18      > RETURN                                                   null

End of function gettotalyears

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.38 ms | 1407 KiB | 16 Q