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

Consolidate functions into class files

Not all legacy applications use a large set of classes. Often, instead of classes, there is a significant number of user-defined functions for core logic.

Using functions is not a problem in itself, but it does mean that we need to include the files where the functions are defined. But autoloading only works for classes. It would be good to find a way to automatically load the function files as well as the class files. That would help us remove even more include calls.

The solution here is to move the functions into class files, and call the functions as static methods on those classes. That way, the autoloader can load up the class file for us, and then we can call the methods in that class.

This procedure ...

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