3v4l.org

run code in 300+ PHP versions simultaneously
<?php \date_default_timezone_set('UTC'); $dates = ['2019-01-18', '2018-12-20', '2019-01-01', null]; echo 'Current Date: ' . date('Y-m-d') . \PHP_EOL; foreach ($dates as $iDate) { $_GET['importDate'] = $iDate; echo 'Import Date of: "' . $iDate . '"' . \PHP_EOL . \PHP_EOL; if (!$start = \date_create(!empty($_GET['importDate']) ? $_GET['importDate'] : 'yesterday')) { die('Invalid Date Supplied'); } //start at the first day of the month $start->modify('first day of this month')->setTime(0,0,0); //validate the current month to prevent future dates if ($start->format('Y-m') === date('Y-m')) { $end = \date_create('yesterday')->setTime(23,59,59); if ($end < $start) { //yesterday was last month $end = clone $start; } } else { $end = clone $start; $end->modify('last day of this month'); } //end at midnight $end->setTime(23,59,59); $importDates = new \DatePeriod($start, new \DateInterval('P1D'), $end); foreach ($importDates as $date) { $dateImport = $date->format('Y-m-d'); echo $dateImport . \PHP_EOL; //... } echo '------' . \PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 97
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 97
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 66
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 65
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 77) Position 1 = 86, Position 2 = 94
Branch analysis from position: 86
2 jumps found. (Code = 78) Position 1 = 87, Position 2 = 94
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 94
Branch analysis from position: 65
Branch analysis from position: 66
2 jumps found. (Code = 77) Position 1 = 86, Position 2 = 94
Branch analysis from position: 86
Branch analysis from position: 94
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
Branch analysis from position: 36
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 97
filename:       /in/S0H6s
function name:  (null)
number of ops:  99
compiled vars:  !0 = $dates, !1 = $iDate, !2 = $start, !3 = $end, !4 = $importDates, !5 = $date, !6 = $dateImport
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'UTC'
          2        DO_ICALL                                                 
    5     3        ASSIGN                                                   !0, <array>
    7     4        INIT_FCALL                                               'date'
          5        SEND_VAL                                                 'Y-m-d'
          6        DO_ICALL                                         $9      
          7        CONCAT                                           ~10     'Current+Date%3A+', $9
          8        CONCAT                                           ~11     ~10, '%0A'
          9        ECHO                                                     ~11
    9    10      > FE_RESET_R                                       $12     !0, ->97
         11    > > FE_FETCH_R                                               $12, !1, ->97
   10    12    >   FETCH_W                      global              $13     '_GET'
         13        ASSIGN_DIM                                               $13, 'importDate'
         14        OP_DATA                                                  !1
   12    15        CONCAT                                           ~15     'Import+Date+of%3A+%22', !1
         16        CONCAT                                           ~16     ~15, '%22'
         17        CONCAT                                           ~17     ~16, '%0A'
         18        CONCAT                                           ~18     ~17, '%0A'
         19        ECHO                                                     ~18
   14    20        INIT_FCALL                                               'date_create'
         21        FETCH_IS                                         ~19     '_GET'
         22        ISSET_ISEMPTY_DIM_OBJ                         1  ~20     ~19, 'importDate'
         23        BOOL_NOT                                         ~21     ~20
         24      > JMPZ                                                     ~21, ->29
         25    >   FETCH_R                      global              ~22     '_GET'
         26        FETCH_DIM_R                                      ~23     ~22, 'importDate'
         27        QM_ASSIGN                                        ~24     ~23
         28      > JMP                                                      ->30
         29    >   QM_ASSIGN                                        ~24     'yesterday'
         30    >   SEND_VAL                                                 ~24
         31        DO_ICALL                                         $25     
         32        ASSIGN                                           ~26     !2, $25
         33        BOOL_NOT                                         ~27     ~26
         34      > JMPZ                                                     ~27, ->36
   15    35    > > EXIT                                                     'Invalid+Date+Supplied'
   18    36    >   INIT_METHOD_CALL                                         !2, 'modify'
         37        SEND_VAL_EX                                              'first+day+of+this+month'
         38        DO_FCALL                                      0  $28     
         39        INIT_METHOD_CALL                                         $28, 'setTime'
         40        SEND_VAL_EX                                              0
         41        SEND_VAL_EX                                              0
         42        SEND_VAL_EX                                              0
         43        DO_FCALL                                      0          
   20    44        INIT_METHOD_CALL                                         !2, 'format'
         45        SEND_VAL_EX                                              'Y-m'
         46        DO_FCALL                                      0  $30     
         47        INIT_FCALL                                               'date'
         48        SEND_VAL                                                 'Y-m'
         49        DO_ICALL                                         $31     
         50        IS_IDENTICAL                                             $30, $31
         51      > JMPZ                                                     ~32, ->66
   21    52    >   INIT_FCALL                                               'date_create'
         53        SEND_VAL                                                 'yesterday'
         54        DO_ICALL                                         $33     
         55        INIT_METHOD_CALL                                         $33, 'setTime'
         56        SEND_VAL_EX                                              23
         57        SEND_VAL_EX                                              59
         58        SEND_VAL_EX                                              59
         59        DO_FCALL                                      0  $34     
         60        ASSIGN                                                   !3, $34
   22    61        IS_SMALLER                                               !3, !2
         62      > JMPZ                                                     ~36, ->65
   24    63    >   CLONE                                            ~37     !2
         64        ASSIGN                                                   !3, ~37
   20    65    > > JMP                                                      ->71
   27    66    >   CLONE                                            ~39     !2
         67        ASSIGN                                                   !3, ~39
   28    68        INIT_METHOD_CALL                                         !3, 'modify'
         69        SEND_VAL_EX                                              'last+day+of+this+month'
         70        DO_FCALL                                      0          
   31    71    >   INIT_METHOD_CALL                                         !3, 'setTime'
         72        SEND_VAL_EX                                              23
         73        SEND_VAL_EX                                              59
         74        SEND_VAL_EX                                              59
         75        DO_FCALL                                      0          
   32    76        NEW                                              $43     'DatePeriod'
         77        SEND_VAR_EX                                              !2
         78        NEW                                              $44     'DateInterval'
         79        SEND_VAL_EX                                              'P1D'
         80        DO_FCALL                                      0          
         81        SEND_VAR_NO_REF_EX                                       $44
         82        SEND_VAR_EX                                              !3
         83        DO_FCALL                                      0          
         84        ASSIGN                                                   !4, $43
   34    85      > FE_RESET_R                                       $48     !4, ->94
         86    > > FE_FETCH_R                                               $48, !5, ->94
   35    87    >   INIT_METHOD_CALL                                         !5, 'format'
         88        SEND_VAL_EX                                              'Y-m-d'
         89        DO_FCALL                                      0  $49     
         90        ASSIGN                                                   !6, $49
   36    91        CONCAT                                           ~51     !6, '%0A'
         92        ECHO                                                     ~51
   34    93      > JMP                                                      ->86
         94    >   FE_FREE                                                  $48
   39    95        ECHO                                                     '------%0A'
    9    96      > JMP                                                      ->11
         97    >   FE_FREE                                                  $12
   40    98      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.05 ms | 1011 KiB | 16 Q