Skip to content
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

Zend\Code\Scanner\MethodScanner does not account for scalar type declarations #27

Closed
weierophinney opened this issue Dec 31, 2019 · 5 comments · Fixed by #58
Closed
Assignees
Labels
Bug Something isn't working Won't Fix This will not be worked on
Milestone

Comments

@weierophinney
Copy link
Member

I believe the issue is with MethodScanner and not ParameterScanner, as this is what is actually parsing the PHP tokens - it correctly ignores non-scalar type declarations such as array and callable. From what I can tell, string, int, bool and float are tokens of type T_STRING. As a result, the scanner believes they are classnames. This can result in classnames that simply don't exist.

I'm not really sure how this can be worked around inside the scanner. As far as I can tell, no PHP version checks are performed on the code being parsed, which means there's no reliable way of detecting whether or not string is an actual classname in PHP <7.0 code, or a scalar type declaration in PHP >=7.0 code.

Perhaps there needs to be some way to globally set the PHP version of the code being scanned?


Originally posted by @djmattyg007 at zendframework/zend-code#56

@weierophinney
Copy link
Member Author

As an aside to this, it would be nice if ParameterScanner and MethodScanner were able to handle non-class type declarations of any form.


Originally posted by @djmattyg007 at zendframework/zend-code#56 (comment)

@weierophinney
Copy link
Member Author

It looks like there's a related issue with classes that have a leading namespace separator. MethodScanner doesn't appear to detect this, and fails to pass the token onto ParameterScanner. ParameterScanner then uses NameInformation to resolve the classname as if it is relative to the current namespace, rather than as an FQCN.

The issue is definitely with MethodScanner. If you create a completely separate instance of ParameterScanner and pass it just the tokens for a single parameter, including the leading T_NS_SEPARATOR token, it will correctly identify the FQCN, and NameInformation will correctly resolve it as an FQCN.


Originally posted by @djmattyg007 at zendframework/zend-code#56 (comment)

@weierophinney
Copy link
Member Author

I've managed to create a patch to resolve the second issue, see #60. The original problem, incorrectly detecting scalar type declarations, is still an issue.


Originally posted by @djmattyg007 at zendframework/zend-code#56 (comment)

@weierophinney
Copy link
Member Author

I had to re-submit the PR as #61.


Originally posted by @djmattyg007 at zendframework/zend-code#56 (comment)

@Ocramius
Copy link
Member

No longer needed as per #58

@Ocramius Ocramius self-assigned this Nov 30, 2020
@Ocramius Ocramius added Bug Something isn't working Won't Fix This will not be worked on labels Nov 30, 2020
@Ocramius Ocramius added this to the 4.0.0 milestone Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Won't Fix This will not be worked on
Projects
None yet
2 participants