3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nextMonth($date, $increment) { $firstOfDateMonth = \DateTime::createFromFormat('Y-m-01', $date); $thirtyFirstOfDateMonth = \DateTime::createFromFormat('Y-m-t', $date); var_dump($thirtyFirstOfDateMonth); $thirtyFirstOfDateMonth = $thirtyFirstOfDateMonth->format('t'); $thirtyFirstOfNextMonth = clone $firstOfDateMonth; $thirtyFirstOfNextMonth->modify('+' . (int) $increment . ' month'); $thirtyFirstOfNextMonth = $thirtyFirstOfNextMonth->format('t'); $dayOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date); $dayOfDateMonth = $dayOfDateMonth->format('d'); $dt = \DateTime::createFromFormat('Y-m-d', $date); $dt->modify('+' . (int) $increment . ' month'); if ($thirtyFirstOfNextMonth < $thirtyFirstOfDateMonth && $thirtyFirstOfNextMonth < $dayOfDateMonth) { $dt = clone $firstOfDateMonth; $dt->modify('+' . (int) $increment . ' month +' . $thirtyFirstOfNextMonth); } return $dt->format('Y-m-d'); } echo nextMonth('2009-12-31', 2),"\n"; echo nextMonth('2010-01-31', 1),"\n"; echo nextMonth('2010-01-05', 1),"\n"; echo nextMonth('2010-12-05', 1),"\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dSLIu
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'nextmonth'
          1        SEND_VAL                                                 '2009-12-31'
          2        SEND_VAL                                                 2
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5        ECHO                                                     '%0A'
   27     6        INIT_FCALL                                               'nextmonth'
          7        SEND_VAL                                                 '2010-01-31'
          8        SEND_VAL                                                 1
          9        DO_FCALL                                      0  $1      
         10        ECHO                                                     $1
         11        ECHO                                                     '%0A'
   28    12        INIT_FCALL                                               'nextmonth'
         13        SEND_VAL                                                 '2010-01-05'
         14        SEND_VAL                                                 1
         15        DO_FCALL                                      0  $2      
         16        ECHO                                                     $2
         17        ECHO                                                     '%0A'
   29    18        INIT_FCALL                                               'nextmonth'
         19        SEND_VAL                                                 '2010-12-05'
         20        SEND_VAL                                                 1
         21        DO_FCALL                                      0  $3      
         22        ECHO                                                     $3
         23        ECHO                                                     '%0A'
         24      > RETURN                                                   1

Function nextmonth:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 53, Position 2 = 55
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 65
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
Branch analysis from position: 55
filename:       /in/dSLIu
function name:  nextMonth
number of ops:  70
compiled vars:  !0 = $date, !1 = $increment, !2 = $firstOfDateMonth, !3 = $thirtyFirstOfDateMonth, !4 = $thirtyFirstOfNextMonth, !5 = $dayOfDateMonth, !6 = $dt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          3        SEND_VAL                                                 'Y-m-01'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !2, $7
    6     7        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          8        SEND_VAL                                                 'Y-m-t'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !3, $9
    7    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                                 
    8    15        INIT_METHOD_CALL                                         !3, 'format'
         16        SEND_VAL_EX                                              't'
         17        DO_FCALL                                      0  $12     
         18        ASSIGN                                                   !3, $12
   10    19        CLONE                                            ~14     !2
         20        ASSIGN                                                   !4, ~14
   11    21        INIT_METHOD_CALL                                         !4, 'modify'
         22        CAST                                          4  ~16     !1
         23        CONCAT                                           ~17     '%2B', ~16
         24        CONCAT                                           ~18     ~17, '+month'
         25        SEND_VAL_EX                                              ~18
         26        DO_FCALL                                      0          
   12    27        INIT_METHOD_CALL                                         !4, 'format'
         28        SEND_VAL_EX                                              't'
         29        DO_FCALL                                      0  $20     
         30        ASSIGN                                                   !4, $20
   14    31        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         32        SEND_VAL                                                 'Y-m-d'
         33        SEND_VAR                                                 !0
         34        DO_FCALL                                      0  $22     
         35        ASSIGN                                                   !5, $22
   15    36        INIT_METHOD_CALL                                         !5, 'format'
         37        SEND_VAL_EX                                              'd'
         38        DO_FCALL                                      0  $24     
         39        ASSIGN                                                   !5, $24
   17    40        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
         41        SEND_VAL                                                 'Y-m-d'
         42        SEND_VAR                                                 !0
         43        DO_FCALL                                      0  $26     
         44        ASSIGN                                                   !6, $26
   18    45        INIT_METHOD_CALL                                         !6, 'modify'
         46        CAST                                          4  ~28     !1
         47        CONCAT                                           ~29     '%2B', ~28
         48        CONCAT                                           ~30     ~29, '+month'
         49        SEND_VAL_EX                                              ~30
         50        DO_FCALL                                      0          
   19    51        IS_SMALLER                                       ~32     !4, !3
         52      > JMPZ_EX                                          ~32     ~32, ->55
         53    >   IS_SMALLER                                       ~33     !4, !5
         54        BOOL                                             ~32     ~33
         55    > > JMPZ                                                     ~32, ->65
   20    56    >   CLONE                                            ~34     !2
         57        ASSIGN                                                   !6, ~34
   21    58        INIT_METHOD_CALL                                         !6, 'modify'
         59        CAST                                          4  ~36     !1
         60        CONCAT                                           ~37     '%2B', ~36
         61        CONCAT                                           ~38     ~37, '+month+%2B'
         62        CONCAT                                           ~39     ~38, !4
         63        SEND_VAL_EX                                              ~39
         64        DO_FCALL                                      0          
   24    65    >   INIT_METHOD_CALL                                         !6, 'format'
         66        SEND_VAL_EX                                              'Y-m-d'
         67        DO_FCALL                                      0  $41     
         68      > RETURN                                                   $41
   25    69*     > RETURN                                                   null

End of function nextmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.46 ms | 1411 KiB | 19 Q