Skip to content

Commit f94518d

Browse files
committed
Merge branch 'PHP-7.3'
* PHP-7.3: Fix #74454: Wrong exception being thrown when using ReflectionMethod
2 parents 8939c4d + 21cd552 commit f94518d

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

ext/reflection/php_reflection.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,8 +2974,10 @@ ZEND_METHOD(reflection_method, __construct)
29742974
switch (Z_TYPE_P(classname)) {
29752975
case IS_STRING:
29762976
if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
2977-
zend_throw_exception_ex(reflection_exception_ptr, 0,
2978-
"Class %s does not exist", Z_STRVAL_P(classname));
2977+
if (!EG(exception)) {
2978+
zend_throw_exception_ex(reflection_exception_ptr, 0,
2979+
"Class %s does not exist", Z_STRVAL_P(classname));
2980+
}
29792981
if (classname == &ztmp) {
29802982
zval_ptr_dtor_str(&ztmp);
29812983
}

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)