What's happening in our world

Blog Post
Coping With Legacy PHP Code
Developers, like any creative individuals, tend to like to work on their own projects from start to finish. There's nothing more satisfying than seeing a project go live that you've shepherded the whole way from conceptual planning to development and testing to that sweet, sweet final build. Sadly, the world doesn't always work that way. Whether you're working as part of a larger development team, you've been brought in to redirect a project that went off the rails or you're updating a project that's been around almost as long as PHP has, at some point in your career you're going to run into code that doesn't shine - and you're still going to have to work with it.
 
At first blush, it can seem pretty overwhelming to pick up a project that's got years of development behind it. As with most actively ongoing PHP projects, the entire codebase has evolved over time as the needs of the client, the user and the technology itself has adjusted over the project's lifespan. Even the language itself has changed dramatically since it was first implemented. Best practices that are commonplace now were barely heard of and rarely used when some projects began, and those that existed at the time were not well known. So what do you do?
 
The most important thing to do is to examine the codebase in its entirety and decide what's most sorely in need of updating. Prioritising your list of updates can make the job seem less like an impossible mountain to climb and actually more like something that might be completed within your lifetime. What sections of code are you going to be working with most directly? Which aspects are so antiquated that they can barely interface with any new code you write? Are there any gaping security holes? Answering these simple questions can provide you with a roadmap of smaller goals that can quickly be completed, giving you a sense of control over the project.

Don't get caught up in a perfectionist mindset. Is it really important for you to start with small-scale optimisation improvements? That can probably wait until some of the larger issues are sorted out. Above all, though - make sure that you follow current PHP best practices when you're implementing your changes, otherwise you - or another programmer a couple of years down the line - are just going to wind up in exactly the same situation as before.
Sign up to receive updates from SourceGuardian
Try our free php source code demo
TRY SOURCEGUARDIAN FREE FOR 14 DAYS
Account Login:

login Forgotten Password?
Connect with us
Bookmark
facebook linkedin twitter rss
© Copyright 2002 - 2024 SourceGuardian Limited
Privacy Policy l Terms & Conditions l Company Info l Contact us l Sitemap l PHP Weekly News