php.net |  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
Votes:1
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
 [2017-04-16 12:19 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-05 12:44 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2018-09-05 12:44 UTC] cmb@php.net
Thank you for the report, and for helping us make PHP better.
 [2018-09-05 13:12 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c0a389a9277070f5ef53c230f34aa5072a9f0985
Log: Fix #74454: Wrong exception being thrown when using ReflectionMethod
 [2018-09-05 13:12 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 17:01:28 2024 UTC