3v4l.org

run code in 300+ PHP versions simultaneously
<?php \date_default_timezone_set('UTC'); $dates = ['2019-01-18', '2019-01-01', '2018-12-01', '2018-12-20', null]; $today = new \DateTimeImmutable('2019-01-01'); $yesterday = $today->modify('-1 day'); $results = []; foreach ($dates as $iDate) { $_GET['importDate'] = $iDate; $results[$iDate] = ''; if (!$start = \date_create(!empty($_GET['importDate']) ? $_GET['importDate'] : $yesterday->format('Y-m-d'))) { die('Invalid Date Supplied'); } if ($start > $today) { $results[$iDate] .= 'Dates set in the future are not permitted' . \PHP_EOL; continue; } //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') === $today->format('Y-m')) { $end = \date_create($yesterday->format('Y-m-d'))->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'); $results[$iDate] .= $dateImport . \PHP_EOL; //... } } //display the results $values = array_reduce(\array_keys($results), function($carry, $item) use ($results) { if (!in_array($results[$item], $carry)) { $carry[] = $results[$item]; } return $carry; }, []); echo 'Current Date: ' . $today->format('Y-m-d') . \PHP_EOL . \PHP_EOL; foreach ($values as $info) { $dates = '"' . implode('", "', array_keys($results, $info)) . '"'; echo <<<EOL Import Dates: $dates $info EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 108
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 108
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 77
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
2 jumps found. (Code = 77) Position 1 = 97, Position 2 = 106
Branch analysis from position: 97
2 jumps found. (Code = 78) Position 1 = 98, Position 2 = 106
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
Branch analysis from position: 106
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 106
Branch analysis from position: 76
Branch analysis from position: 77
2 jumps found. (Code = 77) Position 1 = 97, Position 2 = 106
Branch analysis from position: 97
Branch analysis from position: 106
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
Branch analysis from position: 39
Branch analysis from position: 108
2 jumps found. (Code = 77) Position 1 = 128, Position 2 = 147
Branch analysis from position: 128
2 jumps found. (Code = 78) Position 1 = 129, Position 2 = 147
Branch analysis from position: 129
1 jumps found. (Code = 42) Position 1 = 128
Branch analysis from position: 128
Branch analysis from position: 147
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 147
Branch analysis from position: 108
filename:       /in/ddQG0
function name:  (null)
number of ops:  149
compiled vars:  !0 = $dates, !1 = $today, !2 = $yesterday, !3 = $results, !4 = $iDate, !5 = $start, !6 = $end, !7 = $importDates, !8 = $date, !9 = $dateImport, !10 = $values, !11 = $info
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        NEW                                              $14     'DateTimeImmutable'
          5        SEND_VAL_EX                                              '2019-01-01'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $14
    8     8        INIT_METHOD_CALL                                         !1, 'modify'
          9        SEND_VAL_EX                                              '-1+day'
         10        DO_FCALL                                      0  $17     
         11        ASSIGN                                                   !2, $17
   10    12        ASSIGN                                                   !3, <array>
   11    13      > FE_RESET_R                                       $20     !0, ->108
         14    > > FE_FETCH_R                                               $20, !4, ->108
   12    15    >   FETCH_W                      global              $21     '_GET'
         16        ASSIGN_DIM                                               $21, 'importDate'
         17        OP_DATA                                                  !4
   14    18        ASSIGN_DIM                                               !3, !4
         19        OP_DATA                                                  ''
   16    20        INIT_FCALL                                               'date_create'
         21        FETCH_IS                                         ~24     '_GET'
         22        ISSET_ISEMPTY_DIM_OBJ                         1  ~25     ~24, 'importDate'
         23        BOOL_NOT                                         ~26     ~25
         24      > JMPZ                                                     ~26, ->29
         25    >   FETCH_R                      global              ~27     '_GET'
         26        FETCH_DIM_R                                      ~28     ~27, 'importDate'
         27        QM_ASSIGN                                        ~29     ~28
         28      > JMP                                                      ->33
         29    >   INIT_METHOD_CALL                                         !2, 'format'
         30        SEND_VAL_EX                                              'Y-m-d'
         31        DO_FCALL                                      0  $30     
         32        QM_ASSIGN                                        ~29     $30
         33    >   SEND_VAL                                                 ~29
         34        DO_ICALL                                         $31     
         35        ASSIGN                                           ~32     !5, $31
         36        BOOL_NOT                                         ~33     ~32
         37      > JMPZ                                                     ~33, ->39
   17    38    > > EXIT                                                     'Invalid+Date+Supplied'
   19    39    >   IS_SMALLER                                               !1, !5
         40      > JMPZ                                                     ~34, ->44
   20    41    >   ASSIGN_DIM_OP                .=               8          !3, !4
         42        OP_DATA                                                  'Dates+set+in+the+future+are+not+permitted%0A'
   21    43      > JMP                                                      ->14
   24    44    >   INIT_METHOD_CALL                                         !5, 'modify'
         45        SEND_VAL_EX                                              'first+day+of+this+month'
         46        DO_FCALL                                      0  $36     
         47        INIT_METHOD_CALL                                         $36, 'setTime'
         48        SEND_VAL_EX                                              0
         49        SEND_VAL_EX                                              0
         50        SEND_VAL_EX                                              0
         51        DO_FCALL                                      0          
   26    52        INIT_METHOD_CALL                                         !5, 'format'
         53        SEND_VAL_EX                                              'Y-m'
         54        DO_FCALL                                      0  $38     
         55        INIT_METHOD_CALL                                         !1, 'format'
         56        SEND_VAL_EX                                              'Y-m'
         57        DO_FCALL                                      0  $39     
         58        IS_IDENTICAL                                             $38, $39
         59      > JMPZ                                                     ~40, ->77
   27    60    >   INIT_FCALL                                               'date_create'
         61        INIT_METHOD_CALL                                         !2, 'format'
         62        SEND_VAL_EX                                              'Y-m-d'
         63        DO_FCALL                                      0  $41     
         64        SEND_VAR                                                 $41
         65        DO_ICALL                                         $42     
         66        INIT_METHOD_CALL                                         $42, 'setTime'
         67        SEND_VAL_EX                                              23
         68        SEND_VAL_EX                                              59
         69        SEND_VAL_EX                                              59
         70        DO_FCALL                                      0  $43     
         71        ASSIGN                                                   !6, $43
   28    72        IS_SMALLER                                               !6, !5
         73      > JMPZ                                                     ~45, ->76
   30    74    >   CLONE                                            ~46     !5
         75        ASSIGN                                                   !6, ~46
   26    76    > > JMP                                                      ->82
   33    77    >   CLONE                                            ~48     !5
         78        ASSIGN                                                   !6, ~48
   34    79        INIT_METHOD_CALL                                         !6, 'modify'
         80        SEND_VAL_EX                                              'last+day+of+this+month'
         81        DO_FCALL                                      0          
   37    82    >   INIT_METHOD_CALL                                         !6, 'setTime'
         83        SEND_VAL_EX                                              23
         84        SEND_VAL_EX                                              59
         85        SEND_VAL_EX                                              59
         86        DO_FCALL                                      0          
   38    87        NEW                                              $52     'DatePeriod'
         88        SEND_VAR_EX                                              !5
         89        NEW                                              $53     'DateInterval'
         90        SEND_VAL_EX                                              'P1D'
         91        DO_FCALL                                      0          
         92        SEND_VAR_NO_REF_EX                                       $53
         93        SEND_VAR_EX                                              !6
         94        DO_FCALL                                      0          
         95        ASSIGN                                                   !7, $52
   40    96      > FE_RESET_R                                       $57     !7, ->106
         97    > > FE_FETCH_R                                               $57, !8, ->106
   41    98    >   INIT_METHOD_CALL                                         !8, 'format'
         99        SEND_VAL_EX                                              'Y-m-d'
        100        DO_FCALL                                      0  $58     
        101        ASSIGN                                                   !9, $58
   42   102        CONCAT                                           ~61     !9, '%0A'
        103        ASSIGN_DIM_OP                .=               8          !3, !4
        104        OP_DATA                                                  ~61
   40   105      > JMP                                                      ->97
        106    >   FE_FREE                                                  $57
   11   107      > JMP                                                      ->14
        108    >   FE_FREE                                                  $20
   49   109        INIT_FCALL                                               'array_reduce'
        110        INIT_FCALL                                               'array_keys'
        111        SEND_VAR                                                 !3
        112        DO_ICALL                                         $62     
        113        SEND_VAR                                                 $62
        114        DECLARE_LAMBDA_FUNCTION                          ~63     [0]
        115        BIND_LEXICAL                                             ~63, !3
   55   116        SEND_VAL                                                 ~63
        117        SEND_VAL                                                 <array>
   49   118        DO_ICALL                                         $64     
        119        ASSIGN                                                   !10, $64
   57   120        INIT_METHOD_CALL                                         !1, 'format'
        121        SEND_VAL_EX                                              'Y-m-d'
        122        DO_FCALL                                      0  $66     
        123        CONCAT                                           ~67     'Current+Date%3A+', $66
        124        CONCAT                                           ~68     ~67, '%0A'
        125        CONCAT                                           ~69     ~68, '%0A'
        126        ECHO                                                     ~69
   58   127      > FE_RESET_R                                       $70     !10, ->147
        128    > > FE_FETCH_R                                               $70, !11, ->147
   59   129    >   INIT_FCALL                                               'implode'
        130        SEND_VAL                                                 '%22%2C+%22'
        131        INIT_FCALL                                               'array_keys'
        132        SEND_VAR                                                 !3
        133        SEND_VAR                                                 !11
        134        DO_ICALL                                         $71     
        135        SEND_VAR                                                 $71
        136        DO_ICALL                                         $72     
        137        CONCAT                                           ~73     '%22', $72
        138        CONCAT                                           ~74     ~73, '%22'
        139        ASSIGN                                                   !0, ~74
   61   140        ROPE_INIT                                     5  ~77     'Import+Dates%3A+'
        141        ROPE_ADD                                      1  ~77     ~77, !0
        142        ROPE_ADD                                      2  ~77     ~77, '%0A'
   62   143        ROPE_ADD                                      3  ~77     ~77, !11
        144        ROPE_END                                      4  ~76     ~77, '%0A%0A'
        145        ECHO                                                     ~76
   58   146      > JMP                                                      ->128
        147    >   FE_FREE                                                  $70
   67   148      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ddQG0
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $carry, !1 = $item, !2 = $results
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   50     3        INIT_FCALL                                               'in_array'
          4        FETCH_DIM_R                                      ~3      !2, !1
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        BOOL_NOT                                         ~5      $4
          9      > JMPZ                                                     ~5, ->13
   51    10    >   FETCH_DIM_R                                      ~7      !2, !1
         11        ASSIGN_DIM                                               !0
         12        OP_DATA                                                  ~7
   54    13    > > RETURN                                                   !0
   55    14*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.5 ms | 1022 KiB | 19 Q