O'Reilly logo

Modernizing Legacy Applications in PHP by Paul M. Jones

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Replace global With Dependency Injection

At this point, all of our classes and functions have been consolidated to a central location, and all related include statements have been removed. We would prefer to start writing tests for our classes, but it is very likely that we have a lot of global variables embedded in them. These can cause a lot of trouble via action at a distance where modifying a global in one place changes its value in another place. The next step, then, is to remove all uses of the global keyword from our classes, and inject the necessary dependencies instead.

Note

What Is Dependency Injection?

Dependency injection means that we push our dependencies into a class from the outside, instead of pulling them into a class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required