Modernizing Legacy Applications in PHP: Review

By Bruno Skvorc

Chances are you’ve come across some horrible legacy code once or twice in your lifetime as a PHP developer. Heck, if you’ve worked with WordPress to any degree, I’m sure you have. I myself have had the satisfying task of modernizing a monolithic ZF1 application, and it was the most mentally exhaustive (but, admittedly, the most educational) year of my career.

If only I had had Paul M. Jones’ “Modernizing Legacy Applications In PHP” book back then, I would have been done in half the time, and the work I did would have been twice as good.

The Book

Many thanks to Paul for providing me with a review copy after having read my review of Design Patterns in PHP. The book is a Leanpub publication – meaning it’s self-published – but that’s where similarities with other Leanpub content I’ve consumed so far end.

Modernizing Legacy Applications in PHP is a detailed step by step guide in turning a spaghetti mess of old PHP code you’ve probably inherited from a team that left two generations ago, into a sort of fully fledged MVC application with the front controller, router, dependency injection, and even unit tests.

Happy funny messy eater

Rather than regurgitating common examples found online and various Wikipedia definitions in shortened form, the book takes a hands on approach with sample code eerily similar to things I’ve seen over and over again in legacy projects. This not only verifies a senior developer’s suspicions about the similar state of decrepitude in most legacy apps, but also inspires one to delve deeper as it seems most of us share the same problems at some time and, thus, can use the same solutions.


This book is not for beginners. I mean, if you’re a beginner, I recommend getting it right away and just keeping it in your Leanpub dashboard for when you’ll be able to implicitly recognize the terms discussed within; but if you don’t have a horrible large-scale legacy project or two under your belt before you start reading it, you won’t understand much and ploughing through the content on auto-pilot without knowing what it does is counterproductive at best. Besides, you’ll probably do it wrong because every legacy app is different, despite most of them being similar.

This book is aimed at intermediate and higher level PHP users, with an emphasis on seniors. Intermediate devs won’t get 100% out of it. They’ll understand more of the content, and they’ll be able to use some of it as a prevention against future horrors while working on their apps right now (which, again, is reason enough to recommend a purchase), but intermediate devs are generally still getting familiar with best practices and haven’t been out of the procedural marshes for very long, the mud and sludge still dripping from their “I finally know PHP” shirts.

Schmutziger Junge

The book, however, really shines as a guidebook for professional and higher devs. As someone intimately familiar with all the aspects discussed within, I could approach each chapter as a challenge. Every chapter is named after what we’ll be doing in it – a single phrase summary – which allowed me to imagine the approach I would take in doing it, and then compare it with the solution presented within. Every chapter makes use of modern practices and terms only people with decent amounts of PHP experience are intimately familiar with (unfortunately – let’s work on that!) like IoC, DI, custom FrontController, Routing, URL Rewrites and the still too neglected Unit Testing, and only a seasoned developer will be able to implicitly understand why an approach is needed in a given scenario without questioning the “why”, instead focusing immediately on “how best to”.

Technical Aspect

On a technical level, the book is sound – amazingly so. Each chapter follows a specific step in the modernization process and presents “before” and “after” code. What’s more, the code looks real – it’s not just another “Acme” controller, just another Foo/Bar you’ve seen everywhere.


This looks like it was taken out of a real project which makes it instantly relatable to developers who find themselves in the problems this book solves.

The book is also accompanied by online materials in form of open source classes that get plugged into the modernization process at one time or another and help with bootstrapping some solutions.

The Pros

Apart from what I’ve already listed in previous paragraphs, the author paid much attention to detail, at various places including relevant links to terminology and concepts that might be unfamiliar to the reader. The book is well written, with sentences concise and clear and is a fluent read (except in some cases – see below).

The typos were minimal, and it’s here that I must stress the importance of editing. Leanpub authors, you are not your own worst critic and you are not fit to be your own editor. On that note, neither are your friends, relatives, and so on. If you’re writing a book, you need someone who is either objective or professional enough (preferably both) to give you good, proper feedback (positive or negative), and one who can follow your progress from chapter to chapter. Finding out the book sucks when you’ve already written it helps no one – you can’t rewrite it easily, you can’t change its flow, and generally, you wasted a good opportunity.

Jack-Russel-Terrier mit kaputtem Buch

Paul’s book has been well edited by various parties on various aspects, and it shows. Next to no errors, perfect formatting, best practices, good explanations and excellent examples are what set this book above the typical Leanpub product. Additionally, despite being the lead on the AuraPHP project, Paul made absolutely no effort to get the reader to convert to it, or to use its components in the modernization process. This, along with the other upsides, shows that the book is meant to be a long term quality resource rather than self-promotion.

The Cons

The only downside I could find was that some chapters referenced appendices with code instead of discussing and improving the code inline, which sometimes broke the reading fluency, causing awkward back-and-forth jumps between content – something e-readers and PDF readers have yet to nail down perfectly. If I were to improve anything in a second release, it would be to make sure all chapters follow the approach of the first and last few – embedded code, and no Appendix jumps (though Appendices should still be kept as is, for future reference). This would lengthen the book somewhat, but would allow for a smoother reading experience.


In conclusion – go buy this book now.

Really, on a scale of 5 elephpants I can easily give it a 4.5 (the half an elephpant off just for the “con” I listed above). It’s the perfect guidebook to legacy modernization and I can see myself coming back to it in the future as I meet the coming horrors of old apps.

The book is available on Leanpub, and Paul was kind enough to offer a 10% discount coupon for SitePoint readers. To use it, just hit this link.


I bought this book several months ago and I can attest to how good it is. Along with Working Effectively with Legacy Code by Michael Feathers it has been a great reference tool for working with the projects I have had.

It hasn't been directly applicable to the code I have had to deal with which has been old Code Igniter projects where the developers had no idea what MVC or DRY or any best practices are. But the ideas behind the steps and methods to pull logic from the madness has helped immensely.

Personally, the best thought I've taken away is to not take on a monolith monolithically. Work at chipping away at it and not a full rewrite from scratch.


Right now I read Working Effectively with Legacy Code by Michael Feathers. That's a really great book. How does Modernizing Legacy Applications in PHP compare to it?

I've just read the free sample available on Leanpub, and I did not like it. I did not like the writing style, the advice given was correct, but the description of the steps was rather sketchy. As a professional PHP developer I did not find anything useful in this sample. Everything was obvious, tests were only briefly mentioned without telling how you are supposed to get the code under test in the first place.

That's different in the Michael Feathers' book, because he shows in detail how to get your code under test in order to enable the required change.

Refactoring a large legacy application without a safety net of automated tests is a very scary undertaking. Paraphrasing Michael Feathers, there are two ways to change code: the industry standard edit and pray and cover and modify. Paul M. Jones does not describe (at least in the sampled chapters) how to cover, only how to modify. This amounts to the edit and pray methodology.

The sampled chapters also lack discussion of how to handle the "black voodoo" so prevalent in many legacy code bases. It is not very difficult to find and eliminate all include statements where the included file is explicitly specified, e.g.

require_once 'path/to/file.php';

But in many old and very large legacy apps the paths get calculated based on some voodoo logic and input that your get from user, e.g. read from $_REQUEST. These includes are the ones that make the refactoring difficult. They make it almost impossible to write tests, because old apps tend to have little to no documentation. You cannot test everything after every change, because nobody knows every little feature that exists in the app, not even QA team. And not everything is covered by tests. But your customers still use those features. So, what to do in this case?

This is a very common problem in old software. Unfortunately it doesn't get addressed at all.

Having said that, I am still curious whether other chapters discuss these issues.


Don't judge a book by its [sample chapters]. smile

But yeah, the chapters do discuss testing into more depth, both characterization tests of the legacy mess and the more fine tuned tests of the newly refactored / built components. Though you are right - dynamic includes are a very important part that shouldn't be left out.


I try not to. smile

I ordered a copy now. Let's see whether it is as good as the reviews claim.



Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in PHP, once a week, for free.