Skip to content

Commit dc6703c

Browse files
committed
Address review comments
1 parent 4fb14c3 commit dc6703c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

ext/date/php_date.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
22182218
/* If called from a constructor throw an exception */
22192219
if ((flags & PHP_DATE_INIT_CTOR) && err && err->error_count) {
22202220
/* spit out the first library error message, at least */
2221-
zend_throw_error(zend_ce_exception, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
2221+
zend_throw_exception_ex(NULL, 0, "Failed to parse time string (%s) at position %d (%c): %s", time_str,
22222222
err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message);
22232223
}
22242224
if (err && err->error_count) {
@@ -3691,7 +3691,7 @@ static bool date_interval_initialize(timelib_rel_time **rt, /*const*/ char *form
36913691
timelib_strtointerval(format, format_length, &b, &e, &p, &r, &errors);
36923692

36933693
if (errors->error_count > 0) {
3694-
zend_throw_error(zend_ce_exception, "Unknown or bad format (%s)", format);
3694+
zend_throw_exception_ex(NULL, 0, "Unknown or bad format (%s)", format);
36953695
retval = false;
36963696
if (p) {
36973697
timelib_rel_time_dtor(p);
@@ -3707,7 +3707,7 @@ static bool date_interval_initialize(timelib_rel_time **rt, /*const*/ char *form
37073707
*rt = timelib_diff(b, e);
37083708
retval = true;
37093709
} else {
3710-
zend_throw_error(zend_ce_exception, "Failed to parse interval (%s)", format);
3710+
zend_throw_exception_ex(NULL, 0, "Failed to parse interval (%s)", format);
37113711
retval = false;
37123712
}
37133713
}
@@ -4110,17 +4110,19 @@ PHP_FUNCTION(date_interval_format)
41104110
}
41114111
/* }}} */
41124112

4113-
static void date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, zend_long *recurrences, /*const*/ char *format, size_t format_length) /* {{{ */
4113+
static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, zend_long *recurrences, /*const*/ char *format, size_t format_length) /* {{{ */
41144114
{
41154115
timelib_time *b = NULL, *e = NULL;
41164116
timelib_rel_time *p = NULL;
41174117
int r = 0;
41184118
timelib_error_container *errors;
4119+
bool retval = false;
41194120

41204121
timelib_strtointerval(format, format_length, &b, &e, &p, &r, &errors);
41214122

41224123
if (errors->error_count > 0) {
4123-
zend_throw_error(zend_ce_exception, "Unknown or bad format (%s)", format);
4124+
retval = false;
4125+
zend_throw_exception_ex(NULL, 0, "Unknown or bad format (%s)", format);
41244126
if (b) {
41254127
timelib_time_dtor(b);
41264128
}
@@ -4135,8 +4137,10 @@ static void date_period_initialize(timelib_time **st, timelib_time **et, timelib
41354137
*et = e;
41364138
*d = p;
41374139
*recurrences = r;
4140+
retval = true;
41384141
}
41394142
timelib_error_container_dtor(errors);
4143+
return retval;
41404144
} /* }}} */
41414145

41424146
/* {{{ Creates new DatePeriod object. */
@@ -4163,26 +4167,25 @@ PHP_METHOD(DatePeriod, __construct)
41634167
dpobj->current = NULL;
41644168

41654169
if (isostr) {
4166-
date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len);
4167-
if (EG(exception)) {
4170+
if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len)) {
41684171
RETURN_THROWS();
41694172
}
41704173

41714174
if (dpobj->start == NULL) {
41724175
zend_string *func = get_active_function_or_method_name();
4173-
zend_throw_error(zend_ce_exception, "%s(): ISO interval must contain a start date, \"%s\" given", ZSTR_VAL(func), isostr);
4176+
zend_throw_exception_ex(NULL, 0, "%s(): ISO interval must contain a start date, \"%s\" given", ZSTR_VAL(func), isostr);
41744177
zend_string_release(func);
41754178
RETURN_THROWS();
41764179
}
41774180
if (dpobj->interval == NULL) {
41784181
zend_string *func = get_active_function_or_method_name();
4179-
zend_throw_error(zend_ce_exception, "%s(): ISO interval must contain an interval, \"%s\" given", ZSTR_VAL(func), isostr);
4182+
zend_throw_exception_ex(NULL, 0, "%s(): ISO interval must contain an interval, \"%s\" given", ZSTR_VAL(func), isostr);
41804183
zend_string_release(func);
41814184
RETURN_THROWS();
41824185
}
41834186
if (dpobj->end == NULL && recurrences == 0) {
41844187
zend_string *func = get_active_function_or_method_name();
4185-
zend_throw_error(zend_ce_exception, "%s(): ISO interval must contain an end date or a recurrence count, \"%s\" given", ZSTR_VAL(func), isostr);
4188+
zend_throw_exception_ex(NULL, 0, "%s(): ISO interval must contain an end date or a recurrence count, \"%s\" given", ZSTR_VAL(func), isostr);
41864189
zend_string_release(func);
41874190
RETURN_THROWS();
41884191
}
@@ -4224,7 +4227,7 @@ PHP_METHOD(DatePeriod, __construct)
42244227

42254228
if (dpobj->end == NULL && recurrences < 1) {
42264229
zend_string *func = get_active_function_or_method_name();
4227-
zend_throw_error(zend_ce_exception, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
4230+
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
42284231
zend_string_release(func);
42294232
RETURN_THROWS();
42304233
}

0 commit comments

Comments
 (0)