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/reflection/php_reflection.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/reflection/php_reflection.c')
-rw-r--r-- | ext/reflection/php_reflection.c | 86 |
1 files changed, 26 insertions, 60 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index b4dd978f08..da208f6c4b 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1572,13 +1572,11 @@ ZEND_METHOD(reflection_function, __construct) zval name; zval *object; zval *closure = NULL; - char *lcname; + char *lcname, *nsname; reflection_object *intern; zend_function *fptr; char *name_str; size_t name_len; - int rv; - zend_error_handling zeh; object = getThis(); intern = Z_REFLECTION_P(object); @@ -1590,31 +1588,26 @@ ZEND_METHOD(reflection_function, __construct) fptr = (zend_function*)zend_get_closure_method_def(closure); Z_ADDREF_P(closure); } else { - zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); - zend_restore_error_handling(&zeh TSRMLS_CC); - if (rv == SUCCESS) { - char *nsname; - lcname = zend_str_tolower_dup(name_str, name_len); - - /* Ignore leading "\" */ - nsname = lcname; - if (lcname[0] == '\\') { - nsname = &lcname[1]; - name_len--; - } - - if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) { - efree(lcname); - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Function %s() does not exist", name_str); - return; - } + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { + return; + } + + lcname = zend_str_tolower_dup(name_str, name_len); + + /* Ignore leading "\" */ + nsname = lcname; + if (lcname[0] == '\\') { + nsname = &lcname[1]; + name_len--; + } + + if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) { efree(lcname); - } else { - /* Exception has been thrown. */ + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Function %s() does not exist", name_str); return; } + efree(lcname); } ZVAL_STR_COPY(&name, fptr->common.function_name); @@ -2141,14 +2134,10 @@ ZEND_METHOD(reflection_parameter, __construct) zend_class_entry *ce = NULL; zend_bool is_closure = 0; zend_bool is_invoke = 0; - zend_error_handling zeh; - zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &reference, ¶meter) == FAILURE) { - zend_restore_error_handling(&zeh TSRMLS_CC); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &reference, ¶meter) == FAILURE) { return; } - zend_restore_error_handling(&zeh TSRMLS_CC); object = getThis(); intern = Z_REFLECTION_P(object); @@ -2729,17 +2718,13 @@ ZEND_METHOD(reflection_method, __construct) zval ztmp; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) { - zend_error_handling zeh; - int rv; - - zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); - zend_restore_error_handling(&zeh TSRMLS_CC); - if (rv == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { return; } + if ((tmp = strstr(name_str, "::")) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0, "Invalid method name %s", name_str); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Invalid method name %s", name_str); return; } classname = &ztmp; @@ -4833,14 +4818,7 @@ ZEND_METHOD(reflection_property, __construct) zend_property_info *property_info = NULL; property_reference *reference; - int rv; - zend_error_handling zeh; - - zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len); - zend_restore_error_handling(&zeh TSRMLS_CC); - - if (rv == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) { return; } @@ -5239,15 +5217,9 @@ ZEND_METHOD(reflection_extension, __construct) zend_module_entry *module; char *name_str; size_t name_len; - int rv; - zend_error_handling zeh; ALLOCA_FLAG(use_heap) - zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); - zend_restore_error_handling(&zeh TSRMLS_CC); - - if (rv == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { return; } @@ -5614,14 +5586,8 @@ ZEND_METHOD(reflection_zend_extension, __construct) zend_extension *extension; char *name_str; size_t name_len; - int rv; - zend_error_handling zeh; - - zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); - zend_restore_error_handling(&zeh TSRMLS_CC); - if (rv == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { return; } |