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

End of function nextmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.7 ms | 1407 KiB | 21 Q