Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Zend\Code\Scanner\ClassScanner only properly records the first use statement inside a class #58

Closed
djmattyg007 opened this issue May 7, 2016 · 1 comment

Comments

@djmattyg007
Copy link
Contributor

If you attempt to include multiple traits across multiple use statements within a class, it will not be picked up by ClassScanner. This can be easily verified by modifying test/TestAsset/TestClassUsesTraitSimple.php and modifying it to use two use statements, one for each trait, rather than all in one use statement as it is now. It's worth noting that it doesn't appear to matter how many use statements there are, it will only ever record the traits available in the first statement.

I tried looking into why this was happening, but unfortunately the most sophisticated debugging tools I have available to me at the moment are echo and var_dump. From what I can tell, the parser does find the other use statements, and is even able to work out what the class name is, but it never ends up permanently in $this->infos.

@djmattyg007
Copy link
Contributor Author

Okay, I finally worked out what was going wrong. There are break statements at the end of the main foreach loops in all of the following methods:

  • getTraitNames()
  • getTraitAliases()
  • getVisibilityForAlias()
  • getBlockedTraitMethods()

I can't fathom why they would be there, but they've been there since the code was first committed and released. The result is that once the code finds the first use statement, it terminates. Unless I'm missing something, I should be able to remove them.

There is also a break 2 statement inside the nested foreach loop in getVisibilityForAlias(). I don't know enough about the purpose of the method to understand if that should be left alone, but my inclination is yes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant