Add a linter rule to detect symbols which are aliased with the same name, such as use X\Y\Z as Z. This is unnecessary and is more-simply expressed as use X\Y\Z.
Details
Details
- Reviewers
epriestley - Group Reviewers
Blessed Reviewers - Commits
- rARC6f908f633b7f: Add a linter rule for unnecessary symbol aliases
Added unit tests.
Diff Detail
Diff Detail
- Repository
- rARC Arcanist
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Comment Actions
Just to clarify, if I:
use A; use B; new X();
...where A\X and B\X are valid classes, what is PHP's behavior?
I know it's not an error (like "symbol X is ambiguous"), because that's never PHP's behavior.
And if I then add use B\X as X;, how does PHP's behavior change?
I know it changes, because it's PHP.
Comment Actions
If A and B are namespaces, then use A and use B actually do nothing at all. Actually, these statements will cause a warning to be emitted:
PHP Warning: The use statement with non-compound name 'X' has no effect in /home/josh/workspace/github.com/phacility/libphutil/test.php on line 3 PHP Warning: The use statement with non-compound name 'Y' has no effect in /home/josh/workspace/github.com/phacility/libphutil/test.php on line 4
StackOverflow has a good explanation, but generally I'd avoiding use to "import" a namespace.
A better example would be:
<?php use A\X; use B\X; new X();
This will actually fail though:
PHP Fatal error: Cannot use B\X as X because the name is already in use in /home/josh/workspace/github.com/phacility/libphutil/test.php on line 4