Skip to content

Commit 0064d12

Browse files
committed
Make the error handling of DatePeriod::__construct() more clean
1 parent cf40645 commit 0064d12

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ext/date/php_date.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -4124,7 +4124,6 @@ PHP_METHOD(DatePeriod, __construct)
41244124
timelib_time *clone;
41254125
zend_error_handling error_handling;
41264126

4127-
zend_replace_error_handling(EH_THROW, NULL, &error_handling);
41284127
ZEND_PARSE_PARAMETERS_START(1, 4)
41294128
Z_PARAM_STR_OR_OBJ_OF_CLASS(start_str, start_obj, date_ce_interface)
41304129
Z_PARAM_OPTIONAL
@@ -4139,28 +4138,32 @@ PHP_METHOD(DatePeriod, __construct)
41394138
if (start_str) {
41404139
if (interval_obj) {
41414140
zend_argument_type_error(2, "must be of type ?int when argument #1 ($start) is a string");
4142-
zend_restore_error_handling(&error_handling);
41434141
RETURN_THROWS();
41444142
}
41454143

41464144
if (!end_is_null) {
41474145
zend_argument_value_error(3, "must be null when argument #1 ($start) is a string");
4148-
zend_restore_error_handling(&error_handling);
41494146
RETURN_THROWS();
41504147
}
41514148

41524149
isostr = ZSTR_VAL(start_str);
41534150
isostr_len = ZSTR_LEN(start_str);
41544151

4152+
zend_replace_error_handling(EH_THROW, NULL, &error_handling);
41554153
date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len);
4154+
zend_restore_error_handling(&error_handling);
4155+
41564156
if (dpobj->start == NULL) {
41574157
zend_argument_error(zend_ce_exception, 1, "must contain a start date, \"%s\" given", isostr);
4158+
RETURN_THROWS();
41584159
}
41594160
if (dpobj->interval == NULL) {
41604161
zend_argument_error(zend_ce_exception, 1, "must contain an interval, \"%s\" given", isostr);
4162+
RETURN_THROWS();
41614163
}
41624164
if (dpobj->end == NULL && recurrences == 0) {
41634165
zend_argument_error(zend_ce_exception, 1, "must contain an end date or a recurrence count, \"%s\" given", isostr);
4166+
RETURN_THROWS();
41644167
}
41654168

41664169
if (dpobj->start) {
@@ -4173,13 +4176,11 @@ PHP_METHOD(DatePeriod, __construct)
41734176
} else {
41744177
if (!interval_obj) {
41754178
zend_argument_type_error(2, "must be of type DateInterval when argument #1 ($start) is a DateTimeInterface");
4176-
zend_restore_error_handling(&error_handling);
41774179
RETURN_THROWS();
41784180
}
41794181

41804182
if (end_is_null) {
41814183
zend_argument_type_error(2, "must be of type DateTimeInterface|int when argument #1 ($start) is a DateTimeInterface");
4182-
zend_restore_error_handling(&error_handling);
41834184
RETURN_THROWS();
41844185
}
41854186

@@ -4212,6 +4213,7 @@ PHP_METHOD(DatePeriod, __construct)
42124213

42134214
if (dpobj->end == NULL && recurrences < 1) {
42144215
zend_argument_error(zend_ce_exception, 3, "must be greater than 0");
4216+
RETURN_THROWS();
42154217
}
42164218

42174219
/* options */
@@ -4221,8 +4223,6 @@ PHP_METHOD(DatePeriod, __construct)
42214223
dpobj->recurrences = recurrences + dpobj->include_start_date;
42224224

42234225
dpobj->initialized = 1;
4224-
4225-
zend_restore_error_handling(&error_handling);
42264226
}
42274227
/* }}} */
42284228

0 commit comments

Comments
 (0)