Edit report at https://bugs.php.net/bug.php?id=70282&edit=1
ID: 70282
Updated by: krakjoe@php.net
Reported by: info at dynasource dot eu
Summary: class not shown in reflection exception
-Status: Open
+Status: Not a bug
-Type: Feature/Change Request
+Type: Bug
-Package: Reflection related
+Package: *General Issues
Operating System: W7
PHP Version: 7.0.0beta3
Block user comment: N
Private report: N
New Comment:
I don't think a feature request was being made.
There was a bug fixed that stopped __CLASS__ from working in a Closure declared inside a class,
that's since been fixed.
__CLASS__ has never worked inside a closure, it has no sensible value; Closures are final, it's
only possible semi-truthful value is "Closure", that's not useful. To give it the
value of anything else including __FUNCTION__ would not only be false, but would result in
{closure}.
So it doesn't make sense as a bug, or a feature request.
The issue is resolved anyway, so closing the bug :)
Previous Comments:
------------------------------------------------------------------------
[2015-08-20 11:13:32] requinix@php.net
Repro?
__CLASS__ only works within an actual class because it's a compile-time value. Not evaluated.
If you defined it within a closure within a class, that's fine, but in a closure outside a
class and then evaluated within a class won't work.
And I'm seeing that behavior all the way back to 5.4.0. Except for 7.0.0beta2 which had a bug.
------------------------------------------------------------------------
[2015-08-20 06:38:47] info at dynasource dot eu
agreed.
But this problem did arise because of the variable __CLASS__ not to be working in a Closure. Is this
normal behavior? It breaks backward compatibility.
------------------------------------------------------------------------
[2015-08-19 17:38:59] cmb@php.net
> While I'm here, testing for an empty class name and/or changing
> the message to "Class '%s' does not exist" could help this
> particular case.
I've checked other class related error messages, and it appears
it's customary to have the class name (single-)quoted. As such it
would make sense to change the reflection related error messages
in this regard. However, the other reflection related error
messages would have to be changed as well (properties, functions,
methods etc. should also be quoted), but that would likely break
all 300+ reflection tests, so that's quite some work.
Anyhow, I still don't think the current behavior is a bug,
therefore changing to feature request.
------------------------------------------------------------------------
[2015-08-19 10:07:38] info at dynasource dot eu
correct, it was because of an empty classname.
The reason why it appeared was because of using __CLASS__ within a Closure
------------------------------------------------------------------------
[2015-08-19 07:31:17] requinix@php.net
I assume that's in a browser? Please do a View Source, or a right-click Inspect Element (or
whatever), and check the raw HTML for that message. You will probably see the doubled space
"Class does not exist" that @cmb mentioned. If so then it means $class was empty.
Consider doing a var_dump($class) just before that line, too.
While I'm here, testing for an empty class name and/or changing the message to "Class
'%s' does not exist" could help this particular case.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=70282
--
Edit this bug report at https://bugs.php.net/bug.php?id=70282&edit=1