Skip to content

Commit 7a2c958

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

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
@@ -3010,8 +3010,10 @@ ZEND_METHOD(reflection_method, __construct)
30103010
switch (Z_TYPE_P(classname)) {
30113011
case IS_STRING:
30123012
if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) {
3013-
zend_throw_exception_ex(reflection_exception_ptr, 0,
3014-
"Class %s does not exist", Z_STRVAL_P(classname));
3013+
if (!EG(exception)) {
3014+
zend_throw_exception_ex(reflection_exception_ptr, 0,
3015+
"Class %s does not exist", Z_STRVAL_P(classname));
3016+
}
30153017
if (classname == &ztmp) {
30163018
zval_dtor(&ztmp);
30173019
}

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)