Is Dependency Injection A Standard in PHP and Laravel?

by krubix   Last Updated September 07, 2018 05:05 AM

Or in actuality, how to tell if a certain technique has became a standard in certain language / framework?

As I understood from my readings so far, PHP supports DI in PSR-11 while Laravel uses it out of the box...

But does this mean DI is a standard for PHP and Laravel or they just helped you to do it right, should you choose to use DI?



Answers 1


Or in actuality, how to tell if a certain technique has became a standard in certain language / framework?

Closest thing to a standard in PHP is PSR. Apart from that, all frameworks, libraries and individual programmers have different approaches.

As I understood from my readings so far, PHP supports DI in PSR-11 while Laravel uses it out of the box...

You have misunderstood. Dependency Injection is something that you as a programmer use to properly structure an application, that generally improves testability, readability and maintainability of your code. Any language that supports passing arguments to a function supports dependency injection.

Laravel... actually is generally the inverse of using dependency injection, even though they might advertise featuring a dependency injection container, that is used to instantiate your types. Laravel depends, as far as I know, on the global state for most actions, calls static functions from anywhere, which is the exact contrary of injecting dependencies into a class.

Félix Gagnon-Grenier
Félix Gagnon-Grenier
September 07, 2018 13:38 PM

Related Questions


Difference of how Spring and EJB use IOC

Updated November 29, 2016 08:02 AM