-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect ReflectionClass::getNamespaceName
for anonymous class
#12895
Comments
Hi @kubawerlos. Edit: Oh, sorry. I missed that this is talking about |
This is because Windows paths use backslashes, but the function also uses backslashes to determine where to "cut off" the string: php-src/ext/reflection/php_reflection.c Lines 5456 to 5459 in ec79fc9
Tested on my Windows 10 VM I get the same behaviour as OP. |
And getShortName is also messed up as it'll return "foo.php:8$0". |
Indeed. I think OP would also expect Unix to yield |
Okay, so fixing this would consist of two parts:
WDYT? |
That sounds reasonable. |
"This is intended to display a more useful class name in error messages I guess it doesn't really matter that much, but I did find this. |
@iluuu1994 How do you want to proceed here? I have a working Windows development environment and I already know how to tackle the second bullet point. EDIT: or we could split the issue between us: 2nd bullet point for me and 1st for you? Just let me know so we at least don't do double work ;) |
@nielsdos However you want, I'll focus on something else tomorrow. I'm certainly not mad if you take care of either or both. ^^ I don't think this is high priority though. |
Okay, will tackle this tomorrow. |
…ymous class Because paths can contain backslashes, searching for the first backslash starting on the right for detecting namespaces yields the wrong result. Furthermore, because the namespace of the class is not actually in the name (only the interface or parent class is) the namespace can be wrong. This fix consists of two parts: - Fix how a prefix is chosen such that the correct namespace is included in the name. - If ZEND_ACC_ANON_CLASS is set, check the position of @ and search for the backslash before that. While the issue seems Windows-specific, I could even reproduce this on Linux because Linux allows directories to contain backslashes.
Let's code PHP like there's no tomorrow! 😀 |
Description
The following code:
Resulted in this output:
at Windows and
at Ubuntu
But I expected this output instead:
Reproduced at https://github.com/werlos/php-anonymous-class-namespace (see the only action there).
PHP Version
8.3.0
Operating System
No response
The text was updated successfully, but these errors were encountered: