Make use not clash and crash if the class is already defined #1149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, use will crash with an error if there is already a symbol with the same name defined.
That will generate a fatal error that "bar" already exists in scope:
This is because
usedoes a symbol table lookup to see if there is a collision with any declared class.However, this is a problematic check since inclusion order matters. If the first block is executed after the second one (different files) this will result in code working. If for some reason the inclusion order changes, the code will fail.
Additionally, opcache nulls out the symbol tables prior to compilation. So with opcache enabled, the code (assuming it lives in separate files) will never error, because the symbol table lookups will always fail.
This results in the check being inconsistent at best. It means that the same conceptual code will error if run one way, but not if run several others.
Therefore, I am proposing that we simply remove the error checks all together as the code is perfectly easy to understand and 100% predictable.
This has the side effect that the following code becomes possible: