This RFC hopes to improves PHP namespace implementation by introducing the concept of Grouped Use Declarations:
Grouped use declarations, allow people to group use statements by namespace. Using common PHP library examples, the following use declarations are equivalents:
-
Grouping use statements makes it easier to read that multiple entries are from the same module. For the first example in this RFC, instead of having to read 'FooLibrary\Bar\Baz\Biz' four times to see that the namespace is the same for each entry, it is clear by the grouping syntax that the entries all come from the same namespace.
-
Grouping use statements makes it easier to see in pull requests that a dependency on a new module has been introduced. For example a Pull Request where a new dependency on 'Consolidation' has been introduced:
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\ChoiceQuestion as Choice;
+use Symfony\Component\Console\Question\OptionQuestion;
+use Symfony\Component\Consolidation\Question\OptionQuestion;
use Symfony\Component\Console\Question\Question;
With the current syntax you need to read to the 30th character of the 2nd modified line to realise that the PR adds a new dependency. With the 'batch use' syntax, because the new dependency is not in the same namespace as the existing 'grouped use' statements it can't be slipped into that block.
use Symfony\Component\Console\Question {
ConfirmationQuestion,
ChoiceQuestion as Choice;
+ OptionQuestion,
Question,
};
+use Symfony\Component\Consolidation\Question\OptionQuestion;
The syntax chosen is inline with the current trait adaptation syntax to make it look and feel similar to existing PHP standards.
(Delete the trait example, it adds nothing except confusion - I thought it was for the group use stuff).