diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2018-09-05 15:05:19 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2018-09-05 15:05:19 +0200 |
commit | c0a389a9277070f5ef53c230f34aa5072a9f0985 (patch) | |
tree | af8f724f0176b324986fa79b995971b8dd2c6950 | |
parent | 0f724453c03b7ff500563c019f5dab736d326ad8 (diff) | |
download | php-git-c0a389a9277070f5ef53c230f34aa5072a9f0985.tar.gz |
Fix #74454: Wrong exception being thrown when using ReflectionMethod
If zend_throw_exception_ex() already threw an exception, we should not
throw again.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/reflection/php_reflection.c | 6 | ||||
-rw-r--r-- | ext/reflection/tests/bug74454.inc | 4 | ||||
-rw-r--r-- | ext/reflection/tests/bug74454.phpt | 19 |
4 files changed, 31 insertions, 2 deletions
@@ -9,6 +9,10 @@ PHP NEWS - POSIX: . Fixed bug #75696 (posix_getgrnam fails to print details of group). (cmb) +- Reflection: + . Fixed bug #74454 (Wrong exception being thrown when using ReflectionMethod). + (cmb) + - Standard: . Fixed bug #73457 (Wrong error message when fopen FTP wrapped fails to open data connection). (Ville Hukkamäki) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 690aaa0fe6..bd2d824c38 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3130,8 +3130,10 @@ ZEND_METHOD(reflection_method, __construct) switch (Z_TYPE_P(classname)) { case IS_STRING: if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Class %s does not exist", Z_STRVAL_P(classname)); + if (!EG(exception)) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Class %s does not exist", Z_STRVAL_P(classname)); + } if (classname == &ztmp) { zval_dtor(&ztmp); } diff --git a/ext/reflection/tests/bug74454.inc b/ext/reflection/tests/bug74454.inc new file mode 100644 index 0000000000..5136591367 --- /dev/null +++ b/ext/reflection/tests/bug74454.inc @@ -0,0 +1,4 @@ +<?php +class A { + if (wrongsyntax) +} diff --git a/ext/reflection/tests/bug74454.phpt b/ext/reflection/tests/bug74454.phpt new file mode 100644 index 0000000000..d2d6e88649 --- /dev/null +++ b/ext/reflection/tests/bug74454.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #74454 (Wrong exception being thrown when using ReflectionMethod) +--FILE-- +<?php +spl_autoload_register('load_file'); +try { + $x = new ReflectionMethod('A', 'b'); +} catch (\Throwable $e) { + echo get_class($e), ': ', $e->getMessage(), PHP_EOL; +} + +function load_file() { + require __DIR__ . '/bug74454.inc'; +} +?> +===DONE=== +--EXPECTF-- +ParseError: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST) +===DONE=== |