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

Change instantiation calls

Because we have changed the constructor signature, all the existing instantiations of ItemsGateway are now broken. We need to find all the places in the code where the ItemsGateway class is instantiated, and change the instantiations to pass a properly-constructed Db object and an ItemFactory.

To do so, we use our project-wide search facility to search using a regular expression for our changed class name:

Search for:

new\s+ItemsGateway\(

Doing so will give us a list of all instantiations in the project. We need to review each result and change it by hand to instantiate the dependencies and pass them to the ItemsGateway.

For example, if a page script from the search results looks like this:

page_script.php 1 <?php 2 // ...

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