Skip to content

Commit 6088713

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents ec8457d + 7b1a4e2 commit 6088713

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

ext/date/php_date.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,6 +4639,10 @@ PHP_METHOD(DatePeriod, __construct)
46394639
dpobj->end = clone;
46404640
}
46414641
}
4642+
4643+
if (dpobj->end == NULL && recurrences < 1) {
4644+
php_error_docref(NULL, E_WARNING, "The recurrence count '%d' is invalid. Needs to be > 0", (int) recurrences);
4645+
}
46424646

46434647
/* options */
46444648
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
DatePeriod: Test wrong recurrence parameter on __construct
3+
--FILE--
4+
<?php
5+
try {
6+
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), 0);
7+
} catch (Exception $exception) {
8+
echo $exception->getMessage(), "\n";
9+
}
10+
11+
try {
12+
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'),-1);
13+
} catch (Exception $exception) {
14+
echo $exception->getMessage(), "\n";
15+
}
16+
?>
17+
--EXPECTF--
18+
DatePeriod::__construct(): The recurrence count '0' is invalid. Needs to be > 0
19+
DatePeriod::__construct(): The recurrence count '-1' is invalid. Needs to be > 0

0 commit comments

Comments
 (0)