3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nextMonth($date, $increment) { $firstOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date)->modify('first day of this month'); $thirtyFirstOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date)->modify('last day of this month'); $thirtyFirstOfDateMonthNum = $thirtyFirstOfDateMonth->format('d'); $thirtyFirstOfNextMonth = clone $firstOfDateMonth; $thirtyFirstOfNextMonth->modify('+' . (int) $increment . ' month')->modify('last day of this month'); $thirtyFirstOfNextMonthNum = $thirtyFirstOfNextMonth->format('d'); $dayOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date); $dayOfDateMonthNum = $dayOfDateMonth->format('d'); $dt = \DateTime::createFromFormat('Y-m-d', $date); $dt->modify('+' . (int) $increment . ' month'); if ($thirtyFirstOfNextMonthNum < $thirtyFirstOfDateMonthNum && $thirtyFirstOfNextMonthNum < $dayOfDateMonthNum) { $dt = clone $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"; echo nextMonth('2010-01-31', 13),"\n";

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0140.00318.30
8.3.50.0090.00916.81
8.3.40.0090.00619.11
8.3.30.0150.00018.77
8.3.20.0030.00518.96
8.3.10.0040.00420.68
8.3.00.0080.00017.71
8.2.180.0110.00717.00
8.2.170.0120.00622.96
8.2.160.0060.00822.21
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0160.00319.61
8.2.110.0040.00721.02
8.2.100.0060.00618.03
8.2.90.0030.00619.20
8.2.80.0000.00817.93
8.2.70.0040.00417.86
8.2.60.0040.00418.05
8.2.50.0050.00318.07
8.2.40.0040.00420.07
8.2.30.0040.00418.13
8.2.20.0030.00617.83
8.2.10.0000.00817.84
8.2.00.0030.00518.04
8.1.280.0060.00925.92
8.1.270.0000.00823.99
8.1.260.0080.00026.35
8.1.250.0090.00028.09
8.1.240.0060.00321.06
8.1.230.0000.01220.97
8.1.220.0060.00317.77
8.1.210.0080.00018.85
8.1.200.0100.00017.60
8.1.190.0000.00917.52
8.1.180.0040.00418.10
8.1.170.0000.00818.96
8.1.160.0040.00418.96
8.1.150.0000.00818.93
8.1.140.0000.01017.80
8.1.130.0000.00717.88
8.1.120.0040.00417.75
8.1.110.0060.00317.75
8.1.100.0000.00817.66
8.1.90.0000.01017.71
8.1.80.0040.00417.78
8.1.70.0000.00717.74
8.1.60.0080.00017.85
8.1.50.0000.00817.74
8.1.40.0000.00817.66
8.1.30.0000.00817.84
8.1.20.0000.00817.79
8.1.10.0000.00817.81
8.1.00.0040.00417.79
8.0.300.0000.00720.14
8.0.290.0000.00717.13
8.0.280.0030.00318.62
8.0.270.0050.00217.44
8.0.260.0040.00418.90
8.0.250.0070.00017.17
8.0.240.0000.01017.23
8.0.230.0000.00717.28
8.0.220.0000.00717.10
8.0.210.0050.00217.15
8.0.200.0040.00417.16
8.0.190.0000.00817.21
8.0.180.0000.00717.19
8.0.170.0040.00417.23
8.0.160.0000.00717.15
8.0.150.0040.00417.05
8.0.140.0090.00017.17
8.0.130.0000.00513.51
8.0.120.0000.00717.07
8.0.110.0000.00817.13
8.0.100.0040.00417.15
8.0.90.0000.00817.08
8.0.80.0060.01017.09
8.0.70.0000.00817.18
8.0.60.0030.00517.13
8.0.50.0080.00017.13
8.0.30.0070.01617.30
8.0.20.0120.00817.46
8.0.10.0030.00517.09
8.0.00.0110.00717.13
7.4.330.0030.00314.84
7.4.320.0030.00316.69
7.4.300.0040.00416.82
7.4.290.0030.00316.75
7.4.280.0160.00316.74
7.4.270.0000.00716.78
7.4.260.0000.00913.49
7.4.250.0000.00916.64
7.4.240.0070.00016.88
7.4.230.0040.00416.72
7.4.220.0100.00616.77
7.4.210.0090.00816.73
7.4.200.0050.00216.90
7.4.190.0040.00416.99
7.4.160.0030.01216.89
7.4.150.0050.01417.07
7.4.140.0130.00517.37
7.4.130.0080.00916.75
7.4.120.0050.01216.88
7.4.110.0170.00317.02
7.4.100.0090.01316.75
7.4.90.0120.00616.78
7.4.80.0160.00418.80
7.4.70.0060.00616.82
7.4.60.0100.00716.72
7.4.50.0030.00616.48
7.4.40.0070.00722.05
7.4.30.0100.01016.76
7.4.00.0160.00315.13
7.3.330.0070.00013.33
7.3.320.0000.00713.49
7.3.310.0070.00016.43
7.3.300.0070.00016.54
7.3.290.0100.00316.54
7.3.280.0050.00916.50
7.3.270.0040.01417.07
7.3.260.0140.00618.24
7.3.250.0080.01116.77
7.3.240.0130.00316.69
7.3.230.0100.00616.70
7.3.210.0120.00616.69
7.3.200.0110.00619.39
7.3.190.0000.02016.76
7.3.180.0070.01016.56
7.3.170.0090.00816.80
7.3.160.0030.01216.45
7.3.120.0110.00415.21
7.3.110.0030.01314.74
7.3.100.0070.00714.88
7.3.90.0090.00015.22
7.3.80.0040.00415.05
7.3.70.0070.00415.10
7.3.60.0090.00615.16
7.3.50.0030.00514.94
7.3.40.0070.00415.02
7.3.30.0000.00815.12
7.3.20.0070.00716.97
7.3.10.0030.00916.79
7.3.00.0000.01116.56
7.2.330.0150.01017.16
7.2.320.0140.01016.71
7.2.310.0210.00317.04
7.2.300.0030.01417.07
7.2.290.0030.01316.87
7.2.250.0110.00915.48
7.2.240.0100.01015.07
7.2.230.0030.01215.57
7.2.220.0030.00815.30
7.2.210.0090.00015.25
7.2.200.0040.00415.38
7.2.190.0030.01315.43
7.2.180.0000.01515.32
7.2.170.0000.00915.43
7.2.160.0030.00615.53
7.2.150.0090.00617.14
7.2.140.0000.01216.91
7.2.130.0100.00717.12
7.2.120.0070.00417.09
7.2.110.0080.00516.91
7.2.100.0060.00716.97
7.2.90.0050.01217.03
7.2.80.0070.00717.04
7.2.70.0160.00217.14
7.2.60.0090.00917.08
7.2.50.0080.01117.29
7.2.40.0100.00717.29
7.2.30.0060.00817.15
7.2.20.0100.00617.19
7.2.10.0060.01017.24
7.2.00.0010.01217.16
7.1.330.0060.00616.12
7.1.320.0030.01016.05
7.1.310.0060.00916.03
7.1.300.0050.00515.88
7.1.290.0030.00915.95
7.1.280.0030.01016.13
7.1.270.0090.00615.95
7.1.260.0060.00615.79
7.1.250.0100.00316.05
7.1.240.0040.01315.84
7.1.230.0180.00015.95
7.1.220.0060.00815.91
7.1.210.0110.00616.17
7.1.200.0120.00016.02
7.1.190.0150.00315.91
7.1.180.0050.00816.13
7.1.170.0090.00916.00
7.1.160.0160.00315.95
7.1.150.0140.00315.66
7.1.140.0100.00516.06
7.1.130.0110.00715.95
7.1.120.1310.00015.89
7.1.110.0120.00415.95
7.1.100.0090.00417.01
7.1.90.0070.00716.00
7.1.80.0160.00015.74
7.1.70.0070.00716.59
7.1.60.0150.00517.77
7.1.50.0120.00616.52
7.1.40.0080.00816.11
7.1.30.0120.00916.10
7.1.20.0070.00715.99
7.1.10.0080.00815.65
7.1.00.0080.03619.16
7.0.320.0120.00215.31
7.0.310.0110.00515.75
7.0.300.0120.00415.54
7.0.290.0150.00415.59
7.0.280.0070.00715.62
7.0.270.0160.00015.73
7.0.260.0040.01115.75
7.0.250.0140.00015.56
7.0.240.0140.00015.52
7.0.230.0150.00315.67
7.0.220.0100.00515.59
7.0.210.0040.01215.68
7.0.200.0100.00216.32
7.0.190.0070.00715.66
7.0.180.0090.00415.37
7.0.170.0110.00415.70
7.0.160.0170.00015.56
7.0.150.0110.00415.58
7.0.140.0070.03818.65
7.0.130.0080.00815.76
7.0.120.0050.02018.89
7.0.110.0140.00315.66
7.0.100.0100.00715.45
7.0.90.0100.00315.59
7.0.80.0130.00515.54
7.0.70.0110.00315.34
7.0.60.0070.04217.69
7.0.50.0030.03116.91
7.0.40.0270.03716.79
7.0.30.0250.03716.89
7.0.20.0120.03216.98
7.0.10.0120.03016.88
7.0.00.0180.04016.91
5.6.380.0110.00514.32
5.6.370.0130.00614.50
5.6.360.0080.00814.80
5.6.350.0110.00314.32
5.6.340.0130.00714.16
5.6.330.0070.00614.35
5.6.320.0130.00314.64
5.6.310.0030.01314.55
5.6.300.0110.00714.37
5.6.290.0110.00714.44
5.6.280.0070.04017.89
5.6.270.0150.00314.63
5.6.260.0110.00414.20
5.6.250.0130.00714.49
5.6.240.0110.00714.46
5.6.230.0140.00514.56
5.6.220.0100.00614.69
5.6.210.0160.03917.47
5.6.200.0150.02316.28
5.6.190.0200.04717.41
5.6.180.0160.04817.43
5.6.170.0190.03217.52
5.6.160.0240.03317.49
5.6.150.0290.03317.42
5.6.140.0230.03217.48
5.6.130.0220.04017.35
5.6.120.0170.02617.44
5.6.110.0200.02517.46
5.6.100.0220.02517.44
5.6.90.0200.04217.40
5.6.80.0180.02616.97
5.6.70.0170.03717.12
5.6.60.0220.03117.14
5.6.50.0240.03816.97
5.6.40.0170.04017.12
5.6.30.0180.02917.14
5.6.20.0230.03316.97
5.6.10.0280.03517.16
5.6.00.0170.03616.99
5.5.380.0000.00911.15
5.5.370.0070.00411.58
5.5.360.0040.00811.26
5.5.350.0220.04215.94
5.5.340.0070.03814.57
5.5.330.0230.04115.72
5.5.320.0190.04415.62
5.5.310.0240.02515.82
5.5.300.0290.03315.72
5.5.290.0220.03715.57
5.5.280.0130.02715.66
5.5.270.0170.02515.74
5.5.260.0220.03915.64
5.5.250.0180.02515.67
5.5.240.0190.03915.46
5.5.230.0190.02315.17
5.5.220.0220.03915.32
5.5.210.0220.03615.45
5.5.200.0160.03815.23
5.5.190.0210.02515.48
5.5.180.0220.02915.38
5.5.170.0140.00414.21
5.5.160.0220.03515.46
5.5.150.0170.03515.38
5.5.140.0230.03815.48
5.5.130.0190.03215.38
5.5.120.0160.04215.48
5.5.110.0220.03215.21
5.5.100.0170.04115.16
5.5.90.0230.03315.46
5.5.80.0100.05015.43
5.5.70.0230.03615.42
5.5.60.0180.03115.36
5.5.50.0210.03615.31
5.5.40.0200.04015.28
5.5.30.0240.03615.36
5.5.20.0140.04815.43
5.5.10.0200.02015.46
5.5.00.0160.04515.44
5.4.450.0160.04015.12
5.4.440.0140.02515.40
5.4.430.0200.03515.40
5.4.420.0200.03315.38
5.4.410.0250.03215.26
5.4.400.0220.03515.14
5.4.390.0180.04215.31
5.4.380.0190.03715.05
5.4.370.0190.03815.13
5.4.360.0240.03215.16
5.4.350.0170.03515.09
5.4.340.0150.02215.00
5.4.330.0040.01111.50
5.4.320.0220.03715.01
5.4.310.0160.03315.26
5.4.300.0200.03715.20
5.4.290.0190.03215.18
5.4.280.0190.03715.15
5.4.270.0190.02515.08
5.4.260.0130.03615.09
5.4.250.0160.04315.12
5.4.240.0210.03215.32
5.4.230.0220.03714.96
5.4.220.0230.03115.19
5.4.210.0210.03315.19
5.4.200.0260.03215.19
5.4.190.0190.03515.00
5.4.180.0170.03015.03
5.4.170.0160.03215.03
5.4.160.0200.03415.18
5.4.150.0230.03314.94
5.4.140.0190.03913.85
5.4.130.0200.03213.70
5.4.120.0150.02313.66
5.4.110.0160.03413.78
5.4.100.0160.03613.94
5.4.90.0190.03513.81
5.4.80.0210.03313.92
5.4.70.0160.03213.78
5.4.60.0150.04013.82
5.4.50.0140.02613.76
5.4.40.0190.02413.68
5.4.30.0220.03313.81
5.4.20.0160.01913.69
5.4.10.0160.01713.85
5.4.00.0150.01813.57
5.3.290.0170.03812.82
5.3.280.0180.04012.73
5.3.270.0190.04012.75
5.3.260.0200.03912.70
5.3.250.0210.03112.62
5.3.240.0210.03712.63
5.3.230.0130.03012.58
5.3.220.0170.03912.45
5.3.210.0190.03912.52
5.3.200.0150.02612.58
5.3.190.0210.03712.68
5.3.180.0200.03912.55
5.3.170.0170.02712.72
5.3.160.0180.03712.72
5.3.150.0200.02312.76
5.3.140.0250.03312.71
5.3.130.0180.02512.67
5.3.120.0130.02112.60
5.3.110.0150.02312.62
5.3.100.0130.01912.33
5.3.90.0150.01712.42
5.3.80.0130.02012.37
5.3.70.0080.02312.19
5.3.60.0120.02412.44
5.3.50.0120.02212.33
5.3.40.0160.01712.38
5.3.30.0150.01812.51
5.3.20.0140.01812.29
5.3.10.0120.02212.10
5.3.00.0110.02112.07
5.2.170.0050.02212.07
5.2.160.0090.01712.07
5.2.150.0130.01612.07
5.2.140.0140.01712.07
5.2.130.0140.01312.07
5.2.120.0100.01712.07
5.2.110.0090.01712.07
5.2.100.0100.01812.07
5.2.90.0060.02012.07
5.2.80.0120.01512.07
5.2.70.0130.01512.07
5.2.60.0120.01812.07
5.2.50.0120.01712.07
5.2.40.0100.01612.07
5.2.30.0140.01112.07
5.2.20.0120.01512.07
5.2.10.0120.01212.07
5.2.00.0100.01512.07
5.1.60.0090.01212.07
5.1.50.0110.01412.07
5.1.40.0080.01512.07
5.1.30.0140.01212.07
5.1.20.0120.01212.07
5.1.10.0100.01512.07
5.1.00.0080.01512.07
5.0.50.0060.01212.07
5.0.40.0080.01012.07
5.0.30.0050.01912.07
5.0.20.0060.00812.07
5.0.10.0030.01512.07
5.0.00.0030.01812.07
4.4.90.0050.01112.07
4.4.80.0030.01112.07
4.4.70.0020.01212.07
4.4.60.0030.01212.07
4.4.50.0050.00912.07
4.4.40.0030.01612.07
4.4.30.0060.00912.07
4.4.20.0050.01012.07
4.4.10.0040.01012.07
4.4.00.0070.01212.07
4.3.110.0030.01012.07
4.3.100.0060.00812.07
4.3.90.0020.01012.07
4.3.80.0070.02712.07
4.3.70.0080.01712.07
4.3.60.0100.01212.07
4.3.50.0050.00912.07
4.3.40.0020.01712.07
4.3.30.0020.01012.07
4.3.20.0040.01212.07
4.3.10.0050.02012.07
4.3.00.0050.01312.07

preferences:
41.12 ms | 401 KiB | 5 Q