Skip to content

Commit d507919

Browse files
committed
Revert ZPP changes to DatePeriod::__construct()
1 parent 9243fd1 commit d507919

File tree

2 files changed

+31
-55
lines changed

2 files changed

+31
-55
lines changed

ext/date/php_date.c

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4109,49 +4109,34 @@ static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_
41094109
/* {{{ Creates new DatePeriod object. */
41104110
PHP_METHOD(DatePeriod, __construct)
41114111
{
4112-
php_period_obj *dpobj;
4113-
php_date_obj *dateobj;
4114-
zend_object *start_obj;
4115-
zend_string *start_str;
4116-
zend_object *interval_obj = NULL;
4117-
zend_bool interval_is_null = 1;
4118-
zend_object *end_obj = NULL;
4119-
zend_long recurrences = 0;
4120-
zend_bool end_is_null = 1;
4121-
zend_long options = 0;
4122-
char *isostr;
4123-
size_t isostr_len;
4112+
php_period_obj *dpobj;
4113+
php_date_obj *dateobj;
4114+
zval *start, *end = NULL, *interval;
4115+
zend_long recurrences = 0, options = 0;
4116+
char *isostr = NULL;
4117+
size_t isostr_len = 0;
41244118
timelib_time *clone;
41254119
zend_error_handling error_handling;
41264120

4127-
ZEND_PARSE_PARAMETERS_START(1, 4)
4128-
Z_PARAM_STR_OR_OBJ_OF_CLASS(start_str, start_obj, date_ce_interface)
4129-
Z_PARAM_OPTIONAL
4130-
Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL(interval_obj, date_ce_interval, options, interval_is_null)
4131-
Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL(end_obj, date_ce_interface, recurrences, end_is_null)
4132-
Z_PARAM_LONG(options)
4133-
ZEND_PARSE_PARAMETERS_END();
4121+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OOl|l", &start, date_ce_interface, &interval, date_ce_interval, &recurrences, &options) == FAILURE) {
4122+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OOO|l", &start, date_ce_interface, &interval, date_ce_interval, &end, date_ce_interface, &options) == FAILURE) {
4123+
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s|l", &isostr, &isostr_len, &options) == FAILURE) {
4124+
zend_type_error("DatePeriod::__construct() accepts either (DateTimeInterface, DateInterval, int [, int]) OR (DateTimeInterface, DateInterval, DateTime [, int]) OR (string [, int]) as arguments");
4125+
RETURN_THROWS();
4126+
}
4127+
}
4128+
}
41344129

41354130
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
41364131
dpobj->current = NULL;
41374132

4138-
if (start_str) {
4139-
if (interval_obj) {
4140-
zend_argument_type_error(2, "must be of type ?int when argument #1 ($start) is a string");
4141-
RETURN_THROWS();
4142-
}
4143-
4144-
if (!end_is_null) {
4145-
zend_argument_value_error(3, "must be null when argument #1 ($start) is a string");
4146-
RETURN_THROWS();
4147-
}
4148-
4149-
isostr = ZSTR_VAL(start_str);
4150-
isostr_len = ZSTR_LEN(start_str);
4151-
4133+
if (isostr) {
41524134
zend_replace_error_handling(EH_THROW, NULL, &error_handling);
41534135
date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len);
41544136
zend_restore_error_handling(&error_handling);
4137+
if (EG(exception)) {
4138+
RETURN_THROWS();
4139+
}
41554140

41564141
if (dpobj->start == NULL) {
41574142
zend_argument_error(zend_ce_exception, 1, "must contain a start date, \"%s\" given", isostr);
@@ -4174,21 +4159,11 @@ PHP_METHOD(DatePeriod, __construct)
41744159
}
41754160
dpobj->start_ce = date_ce_date;
41764161
} else {
4177-
if (!interval_obj) {
4178-
zend_argument_type_error(2, "must be of type DateInterval when argument #1 ($start) is a DateTimeInterface");
4179-
RETURN_THROWS();
4180-
}
4181-
4182-
if (end_is_null) {
4183-
zend_argument_type_error(2, "must be of type DateTimeInterface|int when argument #1 ($start) is a DateTimeInterface");
4184-
RETURN_THROWS();
4185-
}
4186-
41874162
/* init */
4188-
php_interval_obj *intobj = php_interval_obj_from_obj(interval_obj);
4163+
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);
41894164

41904165
/* start date */
4191-
dateobj = php_date_obj_from_obj(start_obj);
4166+
dateobj = Z_PHPDATE_P(start);
41924167
clone = timelib_time_ctor();
41934168
memcpy(clone, dateobj->time, sizeof(timelib_time));
41944169
if (dateobj->time->tz_abbr) {
@@ -4198,14 +4173,14 @@ PHP_METHOD(DatePeriod, __construct)
41984173
clone->tz_info = dateobj->time->tz_info;
41994174
}
42004175
dpobj->start = clone;
4201-
dpobj->start_ce = start_obj->ce;
4176+
dpobj->start_ce = Z_OBJCE_P(start);
42024177

42034178
/* interval */
42044179
dpobj->interval = timelib_rel_time_clone(intobj->diff);
42054180

42064181
/* end date */
4207-
if (end_obj) {
4208-
dateobj = php_date_obj_from_obj(end_obj);
4182+
if (end) {
4183+
dateobj = Z_PHPDATE_P(end);
42094184
clone = timelib_time_clone(dateobj->time);
42104185
dpobj->end = clone;
42114186
}

ext/date/tests/DatePeriod_wrong_constructor.phpt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ Havard Eide <[email protected]>
77
date.timezone=UTC
88
--FILE--
99
<?php
10-
new DatePeriod();
10+
11+
try {
12+
new DatePeriod();
13+
} catch (TypeError $exception) {
14+
echo $exception->getMessage() . "\n";
15+
}
1116
?>
12-
--EXPECTF--
13-
Fatal error: Uncaught ArgumentCountError: DatePeriod::__construct() expects at least 1 argument, 0 given in %s:%d
14-
Stack trace:
15-
#0 %s(%d): DatePeriod->__construct()
16-
#1 {main}
17-
thrown in %s on line %d
17+
--EXPECT--
18+
DatePeriod::__construct() accepts either (DateTimeInterface, DateInterval, int [, int]) OR (DateTimeInterface, DateInterval, DateTime [, int]) OR (string [, int]) as arguments

0 commit comments

Comments
 (0)