3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nextMonth($thisMonth, $monthInc) { $firstOfThis = date("Y-m", strtotime($thisMonth)); $dNow = date("t", strtotime($thisMonth)); $dNext = date("t", strtotime($firstOfThis . " +" . $monthInc . " month")); $dDay = date("d", strtotime($thisMonth)); $output = date("Y-m-d",strtotime($thisMonth . " +" . $monthInc . " month")); if ($dNext < $dNow && $dNext < $dDay) { $nextMonth = date("Y-m", strtotime($thisMonth)); $nextMonth = date("Y-m", strtotime($nextMonth . " +" . $monthInc . " month")); $output = $nextMonth . '-' . $dNext; } return $output; } echo nextMonth("2010-01-31",1); exit(); $sample1 = "2010-01-31"; $sample1a = "2010-01-01"; $dnow = date("t",strtotime($sample1)); $dnext = date("t",strtotime($sample1a . " +1 month")); $dday = date("d",strtotime($sample1)); $output = date("Y-m-d",strtotime($sample1 . " +1 month")); echo '/' . $dnow . '/' . $dnext . '/' . $dday . '/'; echo "\n"; if ($dnext < $dnow && $dnext < $dday) { $nextMonth = date("Y-m", strtotime($sample1)); $nextMonth = date("Y-m", strtotime($nextMonth . " +1 month")); $output = $nextMonth . '-' . $dnext; } echo $output; echo "\n"; $ts = strtotime('2010-01-31 +1 month'); echo date('Y-m-d', $ts); echo "\n"; $dt = new \DateTime('2010-01-31'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d'); echo "\n"; $ts = strtotime('2010-01-05 +1 month'); echo date('Y-m-d', $ts); echo "\n"; $dt = new \DateTime('2010-01-05'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/CbS1V
function name:  (null)
number of ops:  127
compiled vars:  !0 = $sample1, !1 = $sample1a, !2 = $dnow, !3 = $dnext, !4 = $dday, !5 = $output, !6 = $nextMonth, !7 = $ts, !8 = $dt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'nextmonth'
          1        SEND_VAL                                                 '2010-01-31'
          2        SEND_VAL                                                 1
          3        DO_FCALL                                      0  $9      
          4        ECHO                                                     $9
   21     5      > EXIT                                                     
   22     6*       ASSIGN                                                   !0, '2010-01-31'
   23     7*       ASSIGN                                                   !1, '2010-01-01'
   24     8*       INIT_FCALL                                               'date'
          9*       SEND_VAL                                                 't'
         10*       INIT_FCALL                                               'strtotime'
         11*       SEND_VAR                                                 !0
         12*       DO_ICALL                                         $12     
         13*       SEND_VAR                                                 $12
         14*       DO_ICALL                                         $13     
         15*       ASSIGN                                                   !2, $13
   25    16*       INIT_FCALL                                               'date'
         17*       SEND_VAL                                                 't'
         18*       INIT_FCALL                                               'strtotime'
         19*       CONCAT                                           ~15     !1, '+%2B1+month'
         20*       SEND_VAL                                                 ~15
         21*       DO_ICALL                                         $16     
         22*       SEND_VAR                                                 $16
         23*       DO_ICALL                                         $17     
         24*       ASSIGN                                                   !3, $17
   26    25*       INIT_FCALL                                               'date'
         26*       SEND_VAL                                                 'd'
         27*       INIT_FCALL                                               'strtotime'
         28*       SEND_VAR                                                 !0
         29*       DO_ICALL                                         $19     
         30*       SEND_VAR                                                 $19
         31*       DO_ICALL                                         $20     
         32*       ASSIGN                                                   !4, $20
   27    33*       INIT_FCALL                                               'date'
         34*       SEND_VAL                                                 'Y-m-d'
         35*       INIT_FCALL                                               'strtotime'
         36*       CONCAT                                           ~22     !0, '+%2B1+month'
         37*       SEND_VAL                                                 ~22
         38*       DO_ICALL                                         $23     
         39*       SEND_VAR                                                 $23
         40*       DO_ICALL                                         $24     
         41*       ASSIGN                                                   !5, $24
   28    42*       CONCAT                                           ~26     '%2F', !2
         43*       CONCAT                                           ~27     ~26, '%2F'
         44*       CONCAT                                           ~28     ~27, !3
         45*       CONCAT                                           ~29     ~28, '%2F'
         46*       CONCAT                                           ~30     ~29, !4
         47*       CONCAT                                           ~31     ~30, '%2F'
         48*       ECHO                                                     ~31
   29    49*       ECHO                                                     '%0A'
   30    50*       IS_SMALLER                                       ~32     !3, !2
         51*       JMPZ_EX                                          ~32     ~32, ->54
         52*       IS_SMALLER                                       ~33     !3, !4
         53*       BOOL                                             ~32     ~33
         54*       JMPZ                                                     ~32, ->75
   32    55*       INIT_FCALL                                               'date'
         56*       SEND_VAL                                                 'Y-m'
         57*       INIT_FCALL                                               'strtotime'
         58*       SEND_VAR                                                 !0
         59*       DO_ICALL                                         $34     
         60*       SEND_VAR                                                 $34
         61*       DO_ICALL                                         $35     
         62*       ASSIGN                                                   !6, $35
   33    63*       INIT_FCALL                                               'date'
         64*       SEND_VAL                                                 'Y-m'
         65*       INIT_FCALL                                               'strtotime'
         66*       CONCAT                                           ~37     !6, '+%2B1+month'
         67*       SEND_VAL                                                 ~37
         68*       DO_ICALL                                         $38     
         69*       SEND_VAR                                                 $38
         70*       DO_ICALL                                         $39     
         71*       ASSIGN                                                   !6, $39
   34    72*       CONCAT                                           ~41     !6, '-'
         73*       CONCAT                                           ~42     ~41, !3
         74*       ASSIGN                                                   !5, ~42
   36    75*       ECHO                                                     !5
   37    76*       ECHO                                                     '%0A'
   39    77*       INIT_FCALL                                               'strtotime'
         78*       SEND_VAL                                                 '2010-01-31+%2B1+month'
         79*       DO_ICALL                                         $44     
         80*       ASSIGN                                                   !7, $44
   40    81*       INIT_FCALL                                               'date'
         82*       SEND_VAL                                                 'Y-m-d'
         83*       SEND_VAR                                                 !7
         84*       DO_ICALL                                         $46     
         85*       ECHO                                                     $46
   41    86*       ECHO                                                     '%0A'
   42    87*       NEW                                              $47     'DateTime'
         88*       SEND_VAL_EX                                              '2010-01-31'
         89*       DO_FCALL                                      0          
         90*       ASSIGN                                                   !8, $47
   43    91*       INIT_METHOD_CALL                                         !8, 'add'
         92*       NEW                                              $50     'DateInterval'
         93*       SEND_VAL_EX                                              'P1M'
         94*       DO_FCALL                                      0          
         95*       SEND_VAR_NO_REF_EX                                       $50
         96*       DO_FCALL                                      0          
   44    97*       INIT_METHOD_CALL                                         !8, 'format'
         98*       SEND_VAL_EX                                              'Y-m-d'
         99*       DO_FCALL                                      0  $53     
        100*       ECHO                                                     $53
   45   101*       ECHO                                                     '%0A'
   46   102*       INIT_FCALL                                               'strtotime'
        103*       SEND_VAL                                                 '2010-01-05+%2B1+month'
        104*       DO_ICALL                                         $54     
        105*       ASSIGN                                                   !7, $54
   47   106*       INIT_FCALL                                               'date'
        107*       SEND_VAL                                                 'Y-m-d'
        108*       SEND_VAR                                                 !7
        109*       DO_ICALL                                         $56     
        110*       ECHO                                                     $56
   48   111*       ECHO                                                     '%0A'
   49   112*       NEW                                              $57     'DateTime'
        113*       SEND_VAL_EX                                              '2010-01-05'
        114*       DO_FCALL                                      0          
        115*       ASSIGN                                                   !8, $57
   50   116*       INIT_METHOD_CALL                                         !8, 'add'
        117*       NEW                                              $60     'DateInterval'
        118*       SEND_VAL_EX                                              'P1M'
        119*       DO_FCALL                                      0          
        120*       SEND_VAR_NO_REF_EX                                       $60
        121*       DO_FCALL                                      0          
   51   122*       INIT_METHOD_CALL                                         !8, 'format'
        123*       SEND_VAL_EX                                              'Y-m-d'
        124*       DO_FCALL                                      0  $63     
        125*       ECHO                                                     $63
        126*     > RETURN                                                   1

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

End of function nextmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.29 ms | 1415 KiB | 18 Q