]> granicus.if.org Git - php/commitdiff
Fix #74454: Wrong exception being thrown when using ReflectionMethod
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 5 Sep 2018 13:05:19 +0000 (15:05 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 5 Sep 2018 13:05:19 +0000 (15:05 +0200)
If zend_throw_exception_ex() already threw an exception, we should not
throw again.

NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug74454.inc [new file with mode: 0644]
ext/reflection/tests/bug74454.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index ea1fd8e76c9e0df035bcc1d6deffe18d353c12bd..50b9d68eddca80bd870bead9dc9b2e8b6b88ce37 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
index 690aaa0fe623291dccc8a94b689287af4ca1145b..bd2d824c382509c3f7a10ccab970720bfa85578b 100644 (file)
@@ -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 (file)
index 0000000..5136591
--- /dev/null
@@ -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 (file)
index 0000000..d2d6e88
--- /dev/null
@@ -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===