Paul M. Jones

There are no solutions, only tradeoffs.

tl;dr of DI vs SL

Chris Hartjes has a nice writeup on dependency injection containers versus service locators. Here's a short way to tell which one you're using:

"If your class has a dependency on a container, you're using Service Locator, not Dependency Injection."

If you have a DI container and you pass it into a class so that class can get its own dependencies from that container, you are *still* doing Service Locator. It doesn't matter that the locator is called a DI container. The key is that the object is pulling in its dependencies, instead of something outside of the object pushing the dependencies into it.

Are you stuck with a legacy PHP application? You should buy my book because it gives you a step-by-step guide to improving you codebase, all while keeping it running the whole time.