summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/php_reflection.c86
-rw-r--r--ext/reflection/tests/ReflectionExtension_constructor_error.phpt9
-rw-r--r--ext/reflection/tests/ReflectionFunction_construct.001.phpt14
-rw-r--r--ext/reflection/tests/ReflectionMethod_006.phpt6
-rw-r--r--ext/reflection/tests/ReflectionMethod_constructor_error2.phpt6
-rw-r--r--ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt2
-rw-r--r--ext/reflection/tests/ReflectionProperty_error.phpt9
7 files changed, 43 insertions, 89 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, &parameter) == FAILURE) {
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &reference, &parameter) == 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;
}
diff --git a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
index f731ab51cc..235c2ad768 100644
--- a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
+++ b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
@@ -7,22 +7,19 @@ Leon Luijkx <leon@phpgg.nl>
<?php
try {
$obj = new ReflectionExtension();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$obj = new ReflectionExtension('foo', 'bar');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$obj = new ReflectionExtension([]);
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt
index 90259ac997..52db7c654d 100644
--- a/ext/reflection/tests/ReflectionFunction_construct.001.phpt
+++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt
@@ -9,31 +9,27 @@ Steve Seear <stevseea@php.net>
try {
$a = new ReflectionFunction(array(1, 2, 3));
echo "exception not thrown.".PHP_EOL;
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction('nonExistentFunction');
-} catch (Exception $e) {
+} catch (ReflectionException $e) {
echo $e->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction(1, 2);
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction([]);
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt
index 0b8228989c..b22a2acc6d 100644
--- a/ext/reflection/tests/ReflectionMethod_006.phpt
+++ b/ext/reflection/tests/ReflectionMethod_006.phpt
@@ -8,14 +8,12 @@ Steve Seear <stevseea@php.net>
try {
new ReflectionMethod();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
new ReflectionMethod('a', 'b', 'c');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
index 85f8097825..3c521efc64 100644
--- a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
+++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
@@ -16,13 +16,13 @@ class TestClass
try {
echo "Too few arguments:\n";
$methodInfo = new ReflectionMethod();
-} catch (ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
echo "\nToo many arguments:\n";
$methodInfo = new ReflectionMethod("TestClass", "foo", true);
-} catch (ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
@@ -45,7 +45,7 @@ try {
try{
//invalid 2nd param
$methodInfo = new ReflectionMethod("TestClass", []);
-} catch (ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
diff --git a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
index 1775dee514..a884162fd2 100644
--- a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
+++ b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
@@ -25,7 +25,7 @@ class C {
try {
new ReflectionParameter(array ('A', 'b'));
}
-catch(ReflectionException $e) {
+catch(TypeException $e) {
printf( "Ok - %s\n", $e->getMessage());
}
diff --git a/ext/reflection/tests/ReflectionProperty_error.phpt b/ext/reflection/tests/ReflectionProperty_error.phpt
index d3910296b5..ef051b5380 100644
--- a/ext/reflection/tests/ReflectionProperty_error.phpt
+++ b/ext/reflection/tests/ReflectionProperty_error.phpt
@@ -9,21 +9,18 @@ class C {
try {
new ReflectionProperty();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
new ReflectionProperty('C::p');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
new ReflectionProperty('C', 'p', 'x');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}