From my understanding PSR 2 only define that there must be an empty line between namespace and use statements and an empty line between the last use statement and the first line of code. There shall not be more than one line to seperate use statements.
PSR 12, which is recommended to follow, imposes a few more rules:
Each block MUST be in the order listed below, although blocks that are not relevant may be omitted.
- Opening <?php tag.
- File-level docblock.
- One or more declare statements.
- The namespace declaration of the file.
- One or more class-based use import statements.
- One or more function-based use import statements.
- One or more constant-based use import statements.
- The remainder of the code in the file.
Which does not strictly define an order of the use statements other than use
before use function
before use const
.
Edit: Example codes appears to recommend use statements to be orded. It does not seem to lead to any order in particular though, as long as multiple imports from a package are not seperated.
use App\Entity\TrainerSeminar;
use App\Entity\User;
use App\EntityTraits\HasContactInformation;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
This would be fine.
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\TrainerSeminar;
use App\Entity\User;
use App\EntityTraits\HasContactInformation;
This would also be fine.
use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use App\EntityTraits\HasContactInformation;
This would not be fine.
use App\Entity\TrainerSeminar;
use App\EntityTraits\HasContactInformation;
use App\Entity\User;
This would also not be fine.