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

Function nextmonth:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 69
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
Branch analysis from position: 48
filename:       /in/AYdN1
function name:  nextMonth
number of ops:  71
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, '+%2B1+month'
         22        SEND_VAL                                                 ~14
         23        DO_ICALL                                         $15     
         24        SEND_VAR                                                 $15
         25        DO_ICALL                                         $16     
         26        ASSIGN                                                   !4, $16
    8    27        INIT_FCALL                                               'date'
         28        SEND_VAL                                                 'd'
         29        INIT_FCALL                                               'strtotime'
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                         $18     
         32        SEND_VAR                                                 $18
         33        DO_ICALL                                         $19     
         34        ASSIGN                                                   !5, $19
    9    35        INIT_FCALL                                               'date'
         36        SEND_VAL                                                 'Y-m-d'
         37        INIT_FCALL                                               'strtotime'
         38        CONCAT                                           ~21     !0, '+%2B1+month'
         39        SEND_VAL                                                 ~21
         40        DO_ICALL                                         $22     
         41        SEND_VAR                                                 $22
         42        DO_ICALL                                         $23     
         43        ASSIGN                                                   !6, $23
   10    44        IS_SMALLER                                       ~25     !4, !3
         45      > JMPZ_EX                                          ~25     ~25, ->48
         46    >   IS_SMALLER                                       ~26     !4, !5
         47        BOOL                                             ~25     ~26
         48    > > JMPZ                                                     ~25, ->69
   12    49    >   INIT_FCALL                                               'date'
         50        SEND_VAL                                                 'Y-m'
         51        INIT_FCALL                                               'strtotime'
         52        SEND_VAR                                                 !0
         53        DO_ICALL                                         $27     
         54        SEND_VAR                                                 $27
         55        DO_ICALL                                         $28     
         56        ASSIGN                                                   !7, $28
   13    57        INIT_FCALL                                               'date'
         58        SEND_VAL                                                 'Y-m'
         59        INIT_FCALL                                               'strtotime'
         60        CONCAT                                           ~30     !7, '+%2B1+month'
         61        SEND_VAL                                                 ~30
         62        DO_ICALL                                         $31     
         63        SEND_VAR                                                 $31
         64        DO_ICALL                                         $32     
         65        ASSIGN                                                   !7, $32
   14    66        CONCAT                                           ~34     !7, '-'
         67        CONCAT                                           ~35     ~34, !4
         68        ASSIGN                                                   !6, ~35
   16    69    > > RETURN                                                   !6
   17    70*     > RETURN                                                   null

End of function nextmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.01 ms | 1415 KiB | 18 Q