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($firstOfThis . " +" . $monthInc . " month")); $output = $nextMonth . '-' . $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/UQ7fe
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 = 67
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
Branch analysis from position: 52
filename:       /in/UQ7fe
function name:  nextMonth
number of ops:  70
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, ->67
   12    53    >   INIT_FCALL                                               'date'
         54        SEND_VAL                                                 'Y-m'
         55        INIT_FCALL                                               'strtotime'
         56        CONCAT                                           ~31     !2, '+%2B'
         57        CONCAT                                           ~32     ~31, !1
         58        CONCAT                                           ~33     ~32, '+month'
         59        SEND_VAL                                                 ~33
         60        DO_ICALL                                         $34     
         61        SEND_VAR                                                 $34
         62        DO_ICALL                                         $35     
         63        ASSIGN                                                   !7, $35
   13    64        CONCAT                                           ~37     !7, '-'
         65        CONCAT                                           ~38     ~37, !4
         66        ASSIGN                                                   !6, ~38
   15    67    >   CONCAT                                           ~40     !6, '%0A'
         68      > RETURN                                                   ~40
   16    69*     > RETURN                                                   null

End of function nextmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.41 ms | 1407 KiB | 21 Q