Bug #74454 [Opn->Ver]: Wrong exception being thrown when using ReflectionMethod
| From: | cmb@php.net | Date: | Wed, 05 Sep 2018 12:44:05 +0000 |
| Subject: | Bug #74454 [Opn->Ver]: Wrong exception being thrown when using ReflectionMethod | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216889@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74454&edit=1
ID: 74454
Updated by: cmb@php.net
Reported by: premavansmuuf at gmail dot com
Summary: Wrong exception being thrown when using
ReflectionMethod
-Status: Open
+Status: Verified
Type: Bug
Package: Reflection related
Operating System: WSL/Ubuntu 16.04
PHP Version: 7.0.18
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2017-04-16 12:19:08] premavansmuuf at gmail dot com
Description:
------------
Trying to get a reflection of method of class located inside a file with syntax error that is being
included via autoloader results in a ReflectionException instead of ParseError.
Note that if one tries
$x = new ReflectionClass('A'); instead, correct
expected ParseError is thrown.
Test script:
---------------
--- FILE index.php
<?php
spl_autoload_register('load_file');
try {
$x = new ReflectionMethod('A', 'b');
} catch (\Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage();
}
function load_file() {
require __DIR__ . '/syntaxerror.php';
}
--- FILE syntaxerror.php
<?php
class A {
if (wrongsyntax)
}
Expected result:
----------------
ParseError: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION)
Actual result:
--------------
ReflectionException: Class A does not exist
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74454&edit=1