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

End of function nextmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.76 ms | 1407 KiB | 17 Q