3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param string $start * @param string $end * * @return string[] */ function date_period_grid($start, $end) { $start = new DateTime($start); $end = new DateTime($end); $i = $end->diff($start); $days = $i->days; $months = $i->y * 12 + $i->m + ($i->d ? 1 : 0); $years = $i->y + (($i->m || $i->d) ? 1 : 0); if ($years > 1) { $period = new DatePeriod($start, new DateInterval('P1Y'), $years); } elseif ($months > 1) { $period = new DatePeriod($start, new DateInterval('P1M'), $months); } else { $period = new DatePeriod($start, new DateInterval('P1D'), $days); } $result = []; foreach ($period as $date) { $result[] = $date->format('Y-m-d'); } return $result; } var_dump(date_period_grid('2012-07-01', '2015-11-01'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CQlI1
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'date_period_grid'
          2        SEND_VAL                                                 '2012-07-01'
          3        SEND_VAL                                                 '2015-11-01'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function date_period_grid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 47) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 50
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 77) Position 1 = 73, Position 2 = 80
Branch analysis from position: 73
2 jumps found. (Code = 78) Position 1 = 74, Position 2 = 80
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 62
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 62
2 jumps found. (Code = 77) Position 1 = 73, Position 2 = 80
Branch analysis from position: 73
Branch analysis from position: 80
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 50
Branch analysis from position: 40
Branch analysis from position: 50
Branch analysis from position: 32
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
Branch analysis from position: 32
filename:       /in/CQlI1
function name:  date_period_grid
number of ops:  83
compiled vars:  !0 = $start, !1 = $end, !2 = $i, !3 = $days, !4 = $months, !5 = $years, !6 = $period, !7 = $result, !8 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        NEW                                              $9      'DateTime'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $9
   12     6        NEW                                              $12     'DateTime'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $12
   14    10        INIT_METHOD_CALL                                         !1, 'diff'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $15     
         13        ASSIGN                                                   !2, $15
   16    14        FETCH_OBJ_R                                      ~17     !2, 'days'
         15        ASSIGN                                                   !3, ~17
   17    16        FETCH_OBJ_R                                      ~19     !2, 'y'
         17        MUL                                              ~20     ~19, 12
         18        FETCH_OBJ_R                                      ~21     !2, 'm'
         19        ADD                                              ~22     ~20, ~21
         20        FETCH_OBJ_R                                      ~23     !2, 'd'
         21      > JMPZ                                                     ~23, ->24
         22    >   QM_ASSIGN                                        ~24     1
         23      > JMP                                                      ->25
         24    >   QM_ASSIGN                                        ~24     0
         25    >   ADD                                              ~25     ~22, ~24
         26        ASSIGN                                                   !4, ~25
   18    27        FETCH_OBJ_R                                      ~27     !2, 'y'
         28        FETCH_OBJ_R                                      ~28     !2, 'm'
         29      > JMPNZ_EX                                         ~28     ~28, ->32
         30    >   FETCH_OBJ_R                                      ~29     !2, 'd'
         31        BOOL                                             ~28     ~29
         32    > > JMPZ                                                     ~28, ->35
         33    >   QM_ASSIGN                                        ~30     1
         34      > JMP                                                      ->36
         35    >   QM_ASSIGN                                        ~30     0
         36    >   ADD                                              ~31     ~27, ~30
         37        ASSIGN                                                   !5, ~31
   20    38        IS_SMALLER                                               1, !5
         39      > JMPZ                                                     ~33, ->50
   21    40    >   NEW                                              $34     'DatePeriod'
         41        SEND_VAR_EX                                              !0
         42        NEW                                              $35     'DateInterval'
         43        SEND_VAL_EX                                              'P1Y'
         44        DO_FCALL                                      0          
         45        SEND_VAR_NO_REF_EX                                       $35
         46        SEND_VAR_EX                                              !5
         47        DO_FCALL                                      0          
         48        ASSIGN                                                   !6, $34
         49      > JMP                                                      ->71
   22    50    >   IS_SMALLER                                               1, !4
         51      > JMPZ                                                     ~39, ->62
   23    52    >   NEW                                              $40     'DatePeriod'
         53        SEND_VAR_EX                                              !0
         54        NEW                                              $41     'DateInterval'
         55        SEND_VAL_EX                                              'P1M'
         56        DO_FCALL                                      0          
         57        SEND_VAR_NO_REF_EX                                       $41
         58        SEND_VAR_EX                                              !4
         59        DO_FCALL                                      0          
         60        ASSIGN                                                   !6, $40
         61      > JMP                                                      ->71
   25    62    >   NEW                                              $45     'DatePeriod'
         63        SEND_VAR_EX                                              !0
         64        NEW                                              $46     'DateInterval'
         65        SEND_VAL_EX                                              'P1D'
         66        DO_FCALL                                      0          
         67        SEND_VAR_NO_REF_EX                                       $46
         68        SEND_VAR_EX                                              !3
         69        DO_FCALL                                      0          
         70        ASSIGN                                                   !6, $45
   28    71    >   ASSIGN                                                   !7, <array>
   29    72      > FE_RESET_R                                       $51     !6, ->80
         73    > > FE_FETCH_R                                               $51, !8, ->80
   30    74    >   INIT_METHOD_CALL                                         !8, 'format'
         75        SEND_VAL_EX                                              'Y-m-d'
         76        DO_FCALL                                      0  $53     
         77        ASSIGN_DIM                                               !7
         78        OP_DATA                                                  $53
   29    79      > JMP                                                      ->73
         80    >   FE_FREE                                                  $51
   33    81      > RETURN                                                   !7
   34    82*     > RETURN                                                   null

End of function date_period_grid

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.1 ms | 1407 KiB | 16 Q