3v4l.org

run code in 300+ PHP versions simultaneously
<?php $date = DateTime::createFromFormat( "Y-m-d", "2025-01-31", new DateTimeZone('UTC') ); echo $date->format('Y-m-d'); echo PHP_EOL; $date->add( new DateInterval('P1M') ); echo $date->format('Y-m-d'); echo PHP_EOL; echo PHP_EOL; $date2 = DateTimeImmutable::createFromFormat( "Y-m-d", "2025-01-31", new DateTimeZone('UTC') ); echo "Current date is : " . $date2->format( 'Y-m-d'); $currentMonth = $date2->format('m'); $nextMonth = $date2->add( new DateInterval('P1M') )->format('m'); if( $currentMonth == $nextMonth-1 && $date2->format('j') != $date2->format('t') ) { $nextDate = $date2->add( new DateInterval('P1M') ); } else { $nextDate = $date2->modify( "last day of next month" ); } echo PHP_EOL; /* $currentMonth = date("m",strtotime($date)); $nextMonth = date("m",strtotime($date."+1 month")); if($currentMonth==$nextMonth-1 && (date("j",strtotime($date)) != date("t",strtotime($date)))){ $nextDate = date('Y-m-d',strtotime($date." +1 month")); }else{ $nextDate = date('Y-m-d', strtotime("last day of next month",strtotime($date))); }*/ echo "Next date would be : {$nextDate->format( 'Y-m-d')}"; echo PHP_EOL; echo PHP_EOL; function addOneMonth( DateTimeImmutable $date ): DateTimeImmutable { $currentMonth = $date->format('m'); $nextMonth = $date->add( new DateInterval('P1M') ); if( $currentMonth == $nextMonth->modify( '-1 month')->format( 'm') && $date->format('j') != $date->format('t') ) { $nextDate = $date->add( new DateInterval('P1M') ); } else { $nextDate = $date->modify( "last day of next month" ); } return $nextDate; } $startDate = DateTimeImmutable::createFromFormat( "Y-m-d", "2024-01-01", new DateTimeZone('UTC') ); $dates = []; for( $i = 0; $i < 368; $i++) { $nextDate = $startDate->add( new DateInterval("P{$i}D") ); echo $nextDate->format('Y-m-d'); echo " - "; $nextMonthStart = addOneMonth( $nextDate ); $endOfPrevMonth = $nextMonthStart->modify( '-1 day' ); echo $endOfPrevMonth->format('Y-m-d'); $daysDiff = $nextDate->diff($endOfPrevMonth)->days + 1; if( $daysDiff > 31 || $daysDiff < 29 ) { echo "PROBLEM!!!!"; } echo " ({$daysDiff}) "; echo " "; echo $nextMonthStart->format('Y-m-d'); echo " "; $nextMonthStartMonthStr = '(0' . ( (int) $nextDate->format('j') + 1) . ')'; $nextMonthStartString = $nextDate->format("Y") . "-" . $nextMonthStartMonthStr . "-" . $nextDate->format("d"); echo " comparing {$nextMonthStart->format('Y-m-d')} to {$nextMonthStartString} "; if( $nextMonthStart->format( 'Y-m-d') !== $nextMonthStartString ) { echo "PROBLEM!!!!"; } echo PHP_EOL; $dates[] = $nextDate; } //print_r($dates);

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 57, Position 2 = 65
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 74
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 186
Branch analysis from position: 186
2 jumps found. (Code = 44) Position 1 = 188, Position 2 = 99
Branch analysis from position: 188
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 99
2 jumps found. (Code = 47) Position 1 = 134, Position 2 = 136
Branch analysis from position: 134
2 jumps found. (Code = 43) Position 1 = 137, Position 2 = 138
Branch analysis from position: 137
2 jumps found. (Code = 43) Position 1 = 181, Position 2 = 182
Branch analysis from position: 181
2 jumps found. (Code = 44) Position 1 = 188, Position 2 = 99
Branch analysis from position: 188
Branch analysis from position: 99
Branch analysis from position: 182
Branch analysis from position: 138
Branch analysis from position: 136
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 186
Branch analysis from position: 186
Branch analysis from position: 65
filename:       /in/KdiOc
function name:  (null)
number of ops:  189
compiled vars:  !0 = $date, !1 = $date2, !2 = $currentMonth, !3 = $nextMonth, !4 = $nextDate, !5 = $startDate, !6 = $dates, !7 = $i, !8 = $nextMonthStart, !9 = $endOfPrevMonth, !10 = $daysDiff, !11 = $nextMonthStartMonthStr, !12 = $nextMonthStartString
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          1        SEND_VAL                                                 'Y-m-d'
          2        SEND_VAL                                                 '2025-01-31'
          3        NEW                                              $13     'DateTimeZone'
          4        SEND_VAL_EX                                              'UTC'
          5        DO_FCALL                                      0          
          6        SEND_VAR                                                 $13
          7        DO_FCALL                                      0  $15     
          8        ASSIGN                                                   !0, $15
    6     9        INIT_METHOD_CALL                                         !0, 'format'
         10        SEND_VAL_EX                                              'Y-m-d'
         11        DO_FCALL                                      0  $17     
         12        ECHO                                                     $17
    8    13        ECHO                                                     '%0A'
   10    14        INIT_METHOD_CALL                                         !0, 'add'
         15        NEW                                              $18     'DateInterval'
         16        SEND_VAL_EX                                              'P1M'
         17        DO_FCALL                                      0          
         18        SEND_VAR_NO_REF_EX                                       $18
         19        DO_FCALL                                      0          
   11    20        INIT_METHOD_CALL                                         !0, 'format'
         21        SEND_VAL_EX                                              'Y-m-d'
         22        DO_FCALL                                      0  $21     
         23        ECHO                                                     $21
   13    24        ECHO                                                     '%0A'
   14    25        ECHO                                                     '%0A'
   21    26        INIT_STATIC_METHOD_CALL                                  'DateTimeImmutable', 'createFromFormat'
         27        SEND_VAL                                                 'Y-m-d'
         28        SEND_VAL                                                 '2025-01-31'
         29        NEW                                              $22     'DateTimeZone'
         30        SEND_VAL_EX                                              'UTC'
         31        DO_FCALL                                      0          
         32        SEND_VAR                                                 $22
         33        DO_FCALL                                      0  $24     
         34        ASSIGN                                                   !1, $24
   23    35        INIT_METHOD_CALL                                         !1, 'format'
         36        SEND_VAL_EX                                              'Y-m-d'
         37        DO_FCALL                                      0  $26     
         38        CONCAT                                           ~27     'Current+date+is+%3A+', $26
         39        ECHO                                                     ~27
   26    40        INIT_METHOD_CALL                                         !1, 'format'
         41        SEND_VAL_EX                                              'm'
         42        DO_FCALL                                      0  $28     
         43        ASSIGN                                                   !2, $28
   27    44        INIT_METHOD_CALL                                         !1, 'add'
         45        NEW                                              $30     'DateInterval'
         46        SEND_VAL_EX                                              'P1M'
         47        DO_FCALL                                      0          
         48        SEND_VAR_NO_REF_EX                                       $30
         49        DO_FCALL                                      0  $32     
         50        INIT_METHOD_CALL                                         $32, 'format'
         51        SEND_VAL_EX                                              'm'
         52        DO_FCALL                                      0  $33     
         53        ASSIGN                                                   !3, $33
   30    54        SUB                                              ~35     !3, 1
         55        IS_EQUAL                                         ~36     !2, ~35
         56      > JMPZ_EX                                          ~36     ~36, ->65
   31    57    >   INIT_METHOD_CALL                                         !1, 'format'
         58        SEND_VAL_EX                                              'j'
         59        DO_FCALL                                      0  $37     
         60        INIT_METHOD_CALL                                         !1, 'format'
         61        SEND_VAL_EX                                              't'
         62        DO_FCALL                                      0  $38     
         63        IS_NOT_EQUAL                                     ~39     $37, $38
         64        BOOL                                             ~36     ~39
         65    > > JMPZ                                                     ~36, ->74
   33    66    >   INIT_METHOD_CALL                                         !1, 'add'
         67        NEW                                              $40     'DateInterval'
         68        SEND_VAL_EX                                              'P1M'
         69        DO_FCALL                                      0          
         70        SEND_VAR_NO_REF_EX                                       $40
         71        DO_FCALL                                      0  $42     
         72        ASSIGN                                                   !4, $42
   30    73      > JMP                                                      ->78
   35    74    >   INIT_METHOD_CALL                                         !1, 'modify'
         75        SEND_VAL_EX                                              'last+day+of+next+month'
         76        DO_FCALL                                      0  $44     
         77        ASSIGN                                                   !4, $44
   37    78    >   ECHO                                                     '%0A'
   52    79        NOP                                                      
         80        INIT_METHOD_CALL                                         !4, 'format'
         81        SEND_VAL_EX                                              'Y-m-d'
         82        DO_FCALL                                      0  $46     
         83        FAST_CONCAT                                      ~47     'Next+date+would+be+%3A+', $46
         84        ECHO                                                     ~47
   56    85        ECHO                                                     '%0A'
   57    86        ECHO                                                     '%0A'
   84    87        INIT_STATIC_METHOD_CALL                                  'DateTimeImmutable', 'createFromFormat'
         88        SEND_VAL                                                 'Y-m-d'
         89        SEND_VAL                                                 '2024-01-01'
         90        NEW                                              $48     'DateTimeZone'
         91        SEND_VAL_EX                                              'UTC'
         92        DO_FCALL                                      0          
         93        SEND_VAR                                                 $48
         94        DO_FCALL                                      0  $50     
         95        ASSIGN                                                   !5, $50
   86    96        ASSIGN                                                   !6, <array>
   88    97        ASSIGN                                                   !7, 0
         98      > JMP                                                      ->186
   90    99    >   INIT_METHOD_CALL                                         !5, 'add'
        100        NEW                                              $54     'DateInterval'
        101        ROPE_INIT                                     3  ~56     'P'
        102        ROPE_ADD                                      1  ~56     ~56, !7
        103        ROPE_END                                      2  ~55     ~56, 'D'
        104        SEND_VAL_EX                                              ~55
        105        DO_FCALL                                      0          
        106        SEND_VAR_NO_REF_EX                                       $54
        107        DO_FCALL                                      0  $59     
        108        ASSIGN                                                   !4, $59
   92   109        INIT_METHOD_CALL                                         !4, 'format'
        110        SEND_VAL_EX                                              'Y-m-d'
        111        DO_FCALL                                      0  $61     
        112        ECHO                                                     $61
   93   113        ECHO                                                     '+-+'
   95   114        INIT_FCALL                                               'addonemonth'
        115        SEND_VAR                                                 !4
        116        DO_FCALL                                      0  $62     
        117        ASSIGN                                                   !8, $62
   96   118        INIT_METHOD_CALL                                         !8, 'modify'
        119        SEND_VAL_EX                                              '-1+day'
        120        DO_FCALL                                      0  $64     
        121        ASSIGN                                                   !9, $64
   98   122        INIT_METHOD_CALL                                         !9, 'format'
        123        SEND_VAL_EX                                              'Y-m-d'
        124        DO_FCALL                                      0  $66     
        125        ECHO                                                     $66
  100   126        INIT_METHOD_CALL                                         !4, 'diff'
        127        SEND_VAR_EX                                              !9
        128        DO_FCALL                                      0  $67     
        129        FETCH_OBJ_R                                      ~68     $67, 'days'
        130        ADD                                              ~69     ~68, 1
        131        ASSIGN                                                   !10, ~69
  102   132        IS_SMALLER                                       ~71     31, !10
        133      > JMPNZ_EX                                         ~71     ~71, ->136
        134    >   IS_SMALLER                                       ~72     !10, 29
        135        BOOL                                             ~71     ~72
        136    > > JMPZ                                                     ~71, ->138
  103   137    >   ECHO                                                     'PROBLEM%21%21%21%21'
  107   138    >   ROPE_INIT                                     3  ~74     '+%28'
        139        ROPE_ADD                                      1  ~74     ~74, !10
        140        ROPE_END                                      2  ~73     ~74, '%29+'
        141        ECHO                                                     ~73
  108   142        ECHO                                                     '++'
  109   143        INIT_METHOD_CALL                                         !8, 'format'
        144        SEND_VAL_EX                                              'Y-m-d'
        145        DO_FCALL                                      0  $76     
        146        ECHO                                                     $76
  110   147        ECHO                                                     '++'
  112   148        INIT_METHOD_CALL                                         !4, 'format'
        149        SEND_VAL_EX                                              'j'
        150        DO_FCALL                                      0  $77     
        151        CAST                                          4  ~78     $77
        152        ADD                                              ~79     ~78, 1
        153        CONCAT                                           ~80     '%280', ~79
        154        CONCAT                                           ~81     ~80, '%29'
        155        ASSIGN                                                   !11, ~81
  115   156        INIT_METHOD_CALL                                         !4, 'format'
        157        SEND_VAL_EX                                              'Y'
        158        DO_FCALL                                      0  $83     
        159        CONCAT                                           ~84     $83, '-'
        160        CONCAT                                           ~85     ~84, !11
        161        CONCAT                                           ~86     ~85, '-'
        162        INIT_METHOD_CALL                                         !4, 'format'
        163        SEND_VAL_EX                                              'd'
        164        DO_FCALL                                      0  $87     
        165        CONCAT                                           ~88     ~86, $87
        166        ASSIGN                                                   !12, ~88
  117   167        ROPE_INIT                                     5  ~92     '+comparing+'
        168        INIT_METHOD_CALL                                         !8, 'format'
        169        SEND_VAL_EX                                              'Y-m-d'
        170        DO_FCALL                                      0  $90     
        171        ROPE_ADD                                      1  ~92     ~92, $90
        172        ROPE_ADD                                      2  ~92     ~92, '+to+'
        173        ROPE_ADD                                      3  ~92     ~92, !12
        174        ROPE_END                                      4  ~91     ~92, '+'
        175        ECHO                                                     ~91
  119   176        INIT_METHOD_CALL                                         !8, 'format'
        177        SEND_VAL_EX                                              'Y-m-d'
        178        DO_FCALL                                      0  $95     
        179        IS_NOT_IDENTICAL                                         !12, $95
        180      > JMPZ                                                     ~96, ->182
  120   181    >   ECHO                                                     'PROBLEM%21%21%21%21'
  125   182    >   ECHO                                                     '%0A'
  127   183        ASSIGN_DIM                                               !6
        184        OP_DATA                                                  !4
   88   185        PRE_INC                                                  !7
        186    >   IS_SMALLER                                               !7, 368
        187      > JMPNZ                                                    ~99, ->99
  131   188    > > RETURN                                                   1

Function addonemonth:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 28
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 37
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/KdiOc
function name:  addOneMonth
number of ops:  45
compiled vars:  !0 = $date, !1 = $currentMonth, !2 = $nextMonth, !3 = $nextDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
   62     1        INIT_METHOD_CALL                                         !0, 'format'
          2        SEND_VAL_EX                                              'm'
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   64     5        INIT_METHOD_CALL                                         !0, 'add'
          6        NEW                                              $6      'DateInterval'
          7        SEND_VAL_EX                                              'P1M'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $6
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !2, $8
   68    12        INIT_METHOD_CALL                                         !2, 'modify'
         13        SEND_VAL_EX                                              '-1+month'
         14        DO_FCALL                                      0  $10     
         15        INIT_METHOD_CALL                                         $10, 'format'
         16        SEND_VAL_EX                                              'm'
         17        DO_FCALL                                      0  $11     
         18        IS_EQUAL                                         ~12     !1, $11
         19      > JMPZ_EX                                          ~12     ~12, ->28
   69    20    >   INIT_METHOD_CALL                                         !0, 'format'
         21        SEND_VAL_EX                                              'j'
         22        DO_FCALL                                      0  $13     
         23        INIT_METHOD_CALL                                         !0, 'format'
         24        SEND_VAL_EX                                              't'
         25        DO_FCALL                                      0  $14     
         26        IS_NOT_EQUAL                                     ~15     $13, $14
         27        BOOL                                             ~12     ~15
         28    > > JMPZ                                                     ~12, ->37
   71    29    >   INIT_METHOD_CALL                                         !0, 'add'
         30        NEW                                              $16     'DateInterval'
         31        SEND_VAL_EX                                              'P1M'
         32        DO_FCALL                                      0          
         33        SEND_VAR_NO_REF_EX                                       $16
         34        DO_FCALL                                      0  $18     
         35        ASSIGN                                                   !3, $18
   68    36      > JMP                                                      ->41
   73    37    >   INIT_METHOD_CALL                                         !0, 'modify'
         38        SEND_VAL_EX                                              'last+day+of+next+month'
         39        DO_FCALL                                      0  $20     
         40        ASSIGN                                                   !3, $20
   76    41    >   VERIFY_RETURN_TYPE                                       !3
         42      > RETURN                                                   !3
   77    43*       VERIFY_RETURN_TYPE                                       
         44*     > RETURN                                                   null

End of function addonemonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
133.9 ms | 1032 KiB | 14 Q