diff --git a/ext/pdo/tests/pdorow.phpt b/ext/pdo/tests/pdorow.phpt index 3b4660423c8..fca40a1ee1a 100644 --- a/ext/pdo/tests/pdorow.phpt +++ b/ext/pdo/tests/pdorow.phpt @@ -18,7 +18,7 @@ catch(PDOException $pe) { } } catch(\Exception $e) { - echo "Failed to "; + echo "Exception throw was not of type PDOException instead was ".get_class($e).PHP_EOL; } ?> diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 80e04046ed1..a01a0d67c56 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1576,6 +1576,8 @@ ZEND_METHOD(reflection_function, __construct) zend_function *fptr; char *name_str; size_t name_len; + int rv; + zend_error_handling zeh; object = getThis(); intern = Z_REFLECTION_P(object); @@ -1586,27 +1588,32 @@ ZEND_METHOD(reflection_function, __construct) if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == SUCCESS) { fptr = (zend_function*)zend_get_closure_method_def(closure); Z_ADDREF_P(closure); - } else if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == 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) { + } 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; + } efree(lcname); - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Function %s() does not exist", name_str); + } else { + //Exception has been thrown. return; } - efree(lcname); - } else { - return; } ZVAL_STR_COPY(&name, fptr->common.function_name); @@ -2128,10 +2135,14 @@ 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); return; } + zend_restore_error_handling(&zeh TSRMLS_CC); object = getThis(); intern = Z_REFLECTION_P(object); @@ -2712,7 +2723,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) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &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) { return; } if ((tmp = strstr(name_str, "::")) == NULL) { diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt index c8e0a17a9d4..90259ac9976 100644 --- a/ext/reflection/tests/ReflectionFunction_construct.001.phpt +++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt @@ -6,18 +6,41 @@ Steve Seear --FILE-- getMessage().PHP_EOL; +} try { $a = new ReflectionFunction('nonExistentFunction'); } catch (Exception $e) { - echo $e->getMessage(); + echo $e->getMessage().PHP_EOL; } -$a = new ReflectionFunction(); -$a = new ReflectionFunction(1, 2); +try { + $a = new ReflectionFunction(); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction(1, 2); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction([]); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + ?> --EXPECTF-- -Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d +Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given Function nonExistentFunction() does not exist -Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d - -Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d +Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 0 given +Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 2 given +Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt index a5164190ca6..0b8228989c7 100644 --- a/ext/reflection/tests/ReflectionMethod_006.phpt +++ b/ext/reflection/tests/ReflectionMethod_006.phpt @@ -6,8 +6,18 @@ Steve Seear --FILE-- getMessage().PHP_EOL; +} +try { + new ReflectionMethod('a', 'b', 'c'); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} class C { public function f() {} @@ -35,21 +45,8 @@ var_dump($rm->getName(1)); ?> --EXPECTF-- -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line %d -object(ReflectionMethod)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} - -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line %d -object(ReflectionMethod)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given Warning: ReflectionMethod::isFinal() expects exactly 0 parameters, 1 given in %s on line %d NULL diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt index 1c2d3a138fc..85f80978254 100644 --- a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt +++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt @@ -16,22 +16,47 @@ class TestClass try { echo "Too few arguments:\n"; $methodInfo = new ReflectionMethod(); -} catch (Exception $e) { - print $e->__toString(); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; } try { echo "\nToo many arguments:\n"; $methodInfo = new ReflectionMethod("TestClass", "foo", true); -} catch (Exception $e) { - print $e->__toString(); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + +try { + //invalid class + $methodInfo = new ReflectionMethod("InvalidClassName", "foo"); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + +try { + //invalid 1st param + $methodInfo = new ReflectionMethod([], "foo"); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try{ + //invalid 2nd param + $methodInfo = new ReflectionMethod("TestClass", []); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; } ?> --EXPECTF-- Too few arguments: - -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12 +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given Too many arguments: +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given +Ok - Class InvalidClassName does not exist +Ok - The parameter class is expected to be either a string or an object +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18 diff --git a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt index 3118c17be8b..1775dee5144 100644 --- a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt +++ b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt @@ -6,7 +6,7 @@ ReflectionParameter::__construct(): Invalid method as constructor // Invalid class name try { new ReflectionParameter (array ('A', 'b'), 0); -} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } +} catch (ReflectionException $e) { echo $e->getMessage()."\n"; } // Invalid class method try { @@ -18,14 +18,31 @@ try { new ReflectionParameter (array (new C, 'b'), 0); } catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } -echo "Done.\n"; class C { } +try { + new ReflectionParameter(array ('A', 'b')); +} +catch(ReflectionException $e) { + printf( "Ok - %s\n", $e->getMessage()); +} + +try { + new ReflectionParameter(0, 0); +} +catch(ReflectionException $e) { + printf( "Ok - %s\n", $e->getMessage()); +} + +echo "Done.\n"; + ?> --EXPECTF-- Class A does not exist Method C::b() does not exist Method C::b() does not exist +Ok - ReflectionParameter::__construct() expects exactly 2 parameters, 1 given +Ok - The parameter class is expected to be either a string, an array(class, method) or a callable object Done.