diff options
author | Nikita Popov <nikic@php.net> | 2015-04-02 18:52:32 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2015-04-06 11:27:34 +0200 |
commit | 122d759618a42bff105971b923fbbb5be02e34b9 (patch) | |
tree | fd4487414ffa3f120c77b19b9eb7dc409659c57e /ext/date/php_date.c | |
parent | 884b0365dbe718f667d048dbc3d1cd9d9f12ab84 (diff) | |
download | php-git-122d759618a42bff105971b923fbbb5be02e34b9.tar.gz |
Always throw TypeException on throwing zpp failures
Introduces a ZEND_PARSE_PARAMS_THROW flag for zpp, which forces to
report FAILURE errors using a TypeException instead of a Warning,
like it would happen in strict mode.
Adds a zend_parse_parameters_throw() convenience function, which
invokes zpp with this flag.
Converts all cases I could identify, where we currently have
throwing zpp usage in constructors and replaces them with this API.
Error handling is still replaced to EH_THROW in some cases to handle
other, domain-specific errors in constructors.
Diffstat (limited to 'ext/date/php_date.c')
-rw-r--r-- | ext/date/php_date.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 8c6b2e5a1f..959ab4896c 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2663,10 +2663,12 @@ PHP_METHOD(DateTime, __construct) size_t time_str_len = 0; zend_error_handling error_handling; - zend_replace_error_handling(EH_THROW, NULL, &error_handling); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1); + if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { + return; } + + zend_replace_error_handling(EH_THROW, NULL, &error_handling); + php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1); zend_restore_error_handling(&error_handling); } /* }}} */ @@ -2681,10 +2683,12 @@ PHP_METHOD(DateTimeImmutable, __construct) size_t time_str_len = 0; zend_error_handling error_handling; - zend_replace_error_handling(EH_THROW, NULL, &error_handling); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1); + if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { + return; } + + zend_replace_error_handling(EH_THROW, NULL, &error_handling); + php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1); zend_restore_error_handling(&error_handling); } /* }}} */ @@ -3641,11 +3645,13 @@ PHP_METHOD(DateTimeZone, __construct) php_timezone_obj *tzobj; zend_error_handling error_handling; - zend_replace_error_handling(EH_THROW, NULL, &error_handling); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) { - tzobj = Z_PHPTIMEZONE_P(getThis()); - timezone_initialize(tzobj, tz); + if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) { + return; } + + zend_replace_error_handling(EH_THROW, NULL, &error_handling); + tzobj = Z_PHPTIMEZONE_P(getThis()); + timezone_initialize(tzobj, tz); zend_restore_error_handling(&error_handling); } /* }}} */ @@ -4070,13 +4076,15 @@ PHP_METHOD(DateInterval, __construct) timelib_rel_time *reltime; zend_error_handling error_handling; + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &interval_string, &interval_string_length) == FAILURE) { + return; + } + zend_replace_error_handling(EH_THROW, NULL, &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &interval_string, &interval_string_length) == SUCCESS) { - if (date_interval_initialize(&reltime, interval_string, interval_string_length) == SUCCESS) { - diobj = Z_PHPINTERVAL_P(getThis()); - diobj->diff = reltime; - diobj->initialized = 1; - } + if (date_interval_initialize(&reltime, interval_string, interval_string_length) == SUCCESS) { + diobj = Z_PHPINTERVAL_P(getThis()); + diobj->diff = reltime; + diobj->initialized = 1; } zend_restore_error_handling(&error_handling); } |