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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: premavansmuuf at gmail dot com
New email:
PHP Version: OS:

 

 [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 Mar 28 17:01:29 2024 UTC