Skip to content

Commit c0a389a

Browse files
committed
Fix #74454: Wrong exception being thrown when using ReflectionMethod
If zend_throw_exception_ex() already threw an exception, we should not throw again.
1 parent 0f72445 commit c0a389a

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
- POSIX:
1010
. Fixed bug #75696 (posix_getgrnam fails to print details of group). (cmb)
1111

12+
- Reflection:
13+
. Fixed bug #74454 (Wrong exception being thrown when using ReflectionMethod).
14+
(cmb)
15+
1216
- Standard:
1317
. Fixed bug #73457 (Wrong error message when fopen FTP wrapped fails to open
1418
data connection). (Ville Hukkamäki)

ext/reflection/php_reflection.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,8 +3130,10 @@ ZEND_METHOD(reflection_method, __construct)
31303130
switch (Z_TYPE_P(classname)) {
31313131
case IS_STRING:
31323132
if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
3133-
zend_throw_exception_ex(reflection_exception_ptr, 0,
3134-
"Class %s does not exist", Z_STRVAL_P(classname));
3133+
if (!EG(exception)) {
3134+
zend_throw_exception_ex(reflection_exception_ptr, 0,
3135+
"Class %s does not exist", Z_STRVAL_P(classname));
3136+
}
31353137
if (classname == &ztmp) {
31363138
zval_dtor(&ztmp);
31373139
}

ext/reflection/tests/bug74454.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
class A {
3+
if (wrongsyntax)
4+
}

ext/reflection/tests/bug74454.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #74454 (Wrong exception being thrown when using ReflectionMethod)
3+
--FILE--
4+
<?php
5+
spl_autoload_register('load_file');
6+
try {
7+
$x = new ReflectionMethod('A', 'b');
8+
} catch (\Throwable $e) {
9+
echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
10+
}
11+
12+
function load_file() {
13+
require __DIR__ . '/bug74454.inc';
14+
}
15+
?>
16+
===DONE===
17+
--EXPECTF--
18+
ParseError: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST)
19+
===DONE===

0 commit comments

Comments
 (0)