|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74454 Wrong exception being thrown when using ReflectionMethod
Submitted: 2017-04-16 12:19 UTC Modified: 2018-09-05 12:44 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: premavansmuuf at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Reflection related
PHP Version: 7.0.18 OS: WSL/Ubuntu 16.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: premavansmuuf at gmail dot com
New email:
PHP Version: OS:


 [2017-04-16 12:19 UTC] premavansmuuf at gmail dot com
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
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
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-05 12:44 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2018-09-05 12:44 UTC]
Thank you for the report, and for helping us make PHP better.
 [2018-09-05 13:12 UTC]
Automatic comment on behalf of
Log: Fix #74454: Wrong exception being thrown when using ReflectionMethod
 [2018-09-05 13:12 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 22 13:01:24 2020 UTC