-
Notifications
You must be signed in to change notification settings - Fork 132
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
AutoloadSourceLocator should know all symbols from a file once a class is autoloaded from that file #617
Comments
Isn't this already handled by looking at loaded files? I don't understand what is not working as it currently is: specifically test scenario needed. The |
Who is handling loaded files in your opinion? Do you mean the case when Nope, it's not that case - because the function isn't loaded in runtime. I think AutoloadSourceLocator is a good place to do it because exactly it follows the autoloading principle, and these functions and constants are discovered only thanks to the autoloading of classes in the same file. Test scenario is straightforward, you have:
I'm not saying if it's a good idea or not, I just wanted to match exactly what PHP does. When |
The As mentioned here and elsewhere, there is a missing component that requires some architectural design. Solving the problem in |
Yeah, centralization would make sense. Locators would be able to push all found symbols into it. |
Correct: something like "traverse and stop when found" with a registry that can be set up independently 👍 |
@ondrejmirtes it's unreal/wrong in case like as: class A {}
const C = 1; file
If we reflect class |
Let's say we have a file that looks like this:
Once the PHP runtime autoloads the class
A
, it also knows aboutb()
andC
which traditionally cannot be autoloaded and wouldn't be discovered otherwise.AutoloadSourceLocator should parse the file with
A
before creating the Reflection and when asked aboutb()
andC
, it should report them as known.I understand if you don't want this change - it makes the behaviour non-deterministic - if the user asks first about
b()
, it will not be known. But I needed this to make the static reflection's behaviour as close to runtime reflection as possible.PoC implementation: phpstan/phpstan-src@25c7791#diff-b84fb81e70db3cdb6b4495c80b475a44
The text was updated successfully, but these errors were encountered: