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.
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.
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.
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”.
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.
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.
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 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.
Frequently Asked Questions (FAQs) about Modernizing Legacy Applications in PHP
What are the key challenges in modernizing legacy applications in PHP?
Modernizing legacy applications in PHP can be a complex process with several challenges. These include understanding the existing codebase, dealing with outdated or deprecated code, ensuring backward compatibility, and managing the risk of introducing new bugs or issues. Additionally, there may be challenges related to the lack of documentation or knowledge about the original system, which can make it difficult to understand the business logic and functionality that needs to be preserved in the modernized application.
How can I ensure the quality of the modernized application?
Ensuring the quality of the modernized application involves rigorous testing throughout the modernization process. This includes unit testing, integration testing, and system testing to validate that the application functions as expected. Additionally, it’s important to follow best practices for coding and design, such as using object-oriented programming and adhering to the SOLID principles, to ensure the maintainability and scalability of the application.
What are the benefits of modernizing legacy applications in PHP?
Modernizing legacy applications in PHP can bring several benefits. These include improved performance, scalability, and security, as well as the ability to leverage the latest features and capabilities of PHP. Additionally, modernized applications are typically easier to maintain and extend, which can reduce the total cost of ownership over time.
How can I manage the risk of modernizing legacy applications?
Managing the risk of modernizing legacy applications involves careful planning and execution. This includes conducting a thorough assessment of the existing application to understand its functionality and dependencies, developing a detailed modernization plan, and implementing the plan in a controlled and iterative manner. Additionally, it’s important to have a robust testing and validation process to catch and fix any issues that arise during the modernization process.
What are the best practices for modernizing legacy applications in PHP?
Best practices for modernizing legacy applications in PHP include following a structured and iterative approach, using object-oriented programming and design patterns, adhering to the SOLID principles, and leveraging the latest features and capabilities of PHP. Additionally, it’s important to ensure that the modernized application is thoroughly tested and validated to ensure its quality and reliability.
How long does it take to modernize a legacy application in PHP?
The time required to modernize a legacy application in PHP can vary widely depending on the complexity of the existing application, the scope of the modernization effort, and the resources available for the project. However, it’s important to note that modernization is typically an iterative process that involves incremental improvements over time, rather than a one-time effort.
Can I modernize a legacy application in PHP without disrupting my business operations?
Yes, it’s possible to modernize a legacy application in PHP without disrupting business operations by following a phased approach. This involves modernizing the application in stages, with each stage focusing on a specific part of the application. This allows the business to continue using the existing application while the modernization effort is underway.
What are the key considerations when choosing a modernization approach for a legacy application in PHP?
Key considerations when choosing a modernization approach for a legacy application in PHP include the complexity of the existing application, the business requirements, the available resources, and the desired outcomes of the modernization effort. Additionally, it’s important to consider the risk and impact of the modernization effort on the business operations.
How can I ensure the security of the modernized application?
Ensuring the security of the modernized application involves following best practices for secure coding, such as validating input, sanitizing output, and using prepared statements for database queries. Additionally, it’s important to conduct regular security audits and vulnerability assessments to identify and fix any potential security issues.
What are the common mistakes to avoid when modernizing a legacy application in PHP?
Common mistakes to avoid when modernizing a legacy application in PHP include rushing the modernization process, neglecting testing and validation, ignoring the business logic and functionality of the existing application, and failing to plan for the ongoing maintenance and support of the modernized application.