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); $interval = $end->diff($start); $days = $interval->days; $months = $interval->y * 12 + $interval->m; $years = intval($end->format('Y')) - intval($start->format('Y')); if ($years > 1) { $period = new DatePeriod($start, new DateInterval('P1Y'), $years); $format = 'Y'; } elseif ($months > 1) { $period = new DatePeriod($start, new DateInterval('P1M'), $months); $format = 'm.Y'; } else { $period = new DatePeriod($start, new DateInterval('P1D'), $days); $format = 'd.m.Y'; } $result = []; foreach ($period as $date) { $result[] = $date->format($format); } return $result; } var_dump(date_period_grid('2012-07-01', '2015-11-01')); var_dump(date_period_grid('2015-01-01', '2015-11-01')); var_dump(date_period_grid('2015-10-01', '2015-11-01'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6J5f5
function name:  (null)
number of ops:  22
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     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                                                 
   41     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'date_period_grid'
          9        SEND_VAL                                                 '2015-01-01'
         10        SEND_VAL                                                 '2015-11-01'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   43    14        INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'date_period_grid'
         16        SEND_VAL                                                 '2015-10-01'
         17        SEND_VAL                                                 '2015-11-01'
         18        DO_FCALL                                      0  $4      
         19        SEND_VAR                                                 $4
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

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

End of function date_period_grid

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.89 ms | 1411 KiB | 18 Q