Field injection (ARCH7200)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key php.quality.field-injection · Severity warning · Category quality
Injecting through fields (via annotations) hides dependencies, breaks immutability, and complicates unit testing. Inject dependencies through the constructor.
Incorrect
Section titled “Incorrect”<?phpclass InvoiceService{ #[Inject] private Mailer $mailer;}Correct
Section titled “Correct”<?phpclass InvoiceService{ public function __construct(private readonly Mailer $mailer) {}}Inject dependencies as constructor parameters instead of using field injection.