Skip to content

Commit 21cd552

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #74454: Wrong exception being thrown when using ReflectionMethod
2 parents 86c930e + 7a2c958 commit 21cd552

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
@@ -20,6 +20,10 @@ PHP NEWS
2020
- POSIX:
2121
Fixed bug #75696 (posix_getgrnam fails to print details of group). (cmb)
2222

23+
- Reflection:
24+
. Fixed bug #74454 (Wrong exception being thrown when using ReflectionMethod).
25+
(cmb)
26+
2327
- Standard:
2428
. Fixed bug #76803 (ftruncate changes file pointer). (Anatol)
2529
. Fixed bug #76818 (Memory corruption and segfault). (Remi)

ext/reflection/php_reflection.c

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

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)