php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66889 ReflectionException message should have quotes around class name
Submitted: 2014-03-12 11:16 UTC Modified: 2021-10-08 14:24 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sam at rmcreative dot ru Assigned: cmb (profile)
Status: Closed Package: Reflection related
PHP Version: 5.4.26 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 + 47 = ?
Subscribe to this entry?

 
 [2014-03-12 11:16 UTC] sam at rmcreative dot ru
Description:
------------
Currently if there's a space in class name such as new \ReflectionClass('\hey\there\is\Space '), it's very hard to get it from error message:

Fatal error: Uncaught exception 'ReflectionException' with message 'Class \hey\t
here\is\Space  does not exist' in ...

Would be great to have it like the following:

Fatal error: Uncaught exception 'ReflectionException' with message 'Class "\hey\t
here\is\Space " does not exist' in ...

Test script:
---------------
<?php
new \ReflectionClass('\hey\there\is\Space ');

Expected result:
----------------
Exception with class name in quotes

Actual result:
--------------
Exception with class name w/o quotes

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-12 17:21 UTC] requinix@php.net
Don't parse error messages for information.

If you want to know if a class exists then use class_exists(). If you don't like that then use a try/catch block. Of course there's also the question of why your code is trying to reflect an invalid class.

$class = '\hey\there\is\Space ';
try {
  new ReflectionClass($class);
} catch (ReflectionException $re) {
  echo "'{$class}' does not exist";
}
 [2014-03-17 21:37 UTC] sam at rmcreative dot ru
I'm not parsing it. I'm reading it as a human.

The cause of such error is a typo.
 [2021-10-08 14:24 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-10-08 14:24 UTC] cmb@php.net
This is resolved as of PHP 8.0.0[1].

[1] <https://3v4l.org/QRMcI>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC