Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Upgrading Old PHP Versions Safely With Rector and CI

In almost every legacy PHP project Loop Origin takes on, the first question is the same: which PHP version is production on? The answer is often 7.2 or 7.4, sometimes 5.6, on a server nobody wants to touch. PHP 7.4 reached end of life in November 2022, and PHP 8.0 followed a year later, so these apps run without security fixes and block every modern package. The team knows it. The upgrade keeps…

Upgrading an older PHP application to a newer version can be a risky endeavor. However, by employing a strategic approach, it is possible to perform the upgrade in a safe and controlled manner. The process begins with identifying the PHP version currently running in production and then setting up continuous integration (CI) with the goal of running tests on both the existing and target PHP versions. This allows for a side-by-side comparison of code behavior.

To facilitate this, tools such as PHPCompatibility, PHPStan, and Rector are utilized. PHPCompatibility identifies code changes required for a specific PHP version, while PHPStan detects type errors and undefined methods. Rector performs the actual refactoring by applying mechanical code changes in small batches, ensuring that the application remains functional throughout the process.

An essential step in the upgrade is creating a safety net through thorough testing. Characterization tests are written to capture the application's behavior under normal conditions, allowing for detection of any changes resulting from the upgrade. Once the safety net is established, CI is set up to run tests on both the current and target PHP versions, ensuring that code passes on both platforms.

With the testing framework in place, Rector is employed to automate the refactoring process. This tool handles tasks such as converting loops, updating string offsets, removing deprecated functions, and more. By configuring Rector to work with the existing version first and then progressively targeting newer versions, the refactoring process becomes manageable and incremental. The developer reviews the generated changes before applying them, typically on a module-by-module basis.

During the upgrade, certain issues may arise that require manual intervention. For example, PHP 8 introduces changes such as stricter string-to-number comparisons, warnings that now trigger errors, and the removal of certain deprecated functions. Dependencies also need to be updated one at a time, ensuring compatibility with the new PHP version. After each change, the application is thoroughly tested to verify that it remains stable and functional.

By following this structured approach, upgrading an old PHP application to a newer version becomes a series of incremental steps rather than a daunting leap. This methodical process minimizes risk, allows for continuous monitoring, and ultimately results in a modernized application that benefits from the latest PHP features and security enhancements.

Rewritten by urgent.news; may contain errors — check the original.

Read the original at dev.to →

Report a problem with this story

More in Tech

Trap Streets for Code: How Mapmakers Caught Copiers, and How I Do It in Git

In the 1920s, two mapmakers at General Drafting, Otto G. Lindberg and Ernest Alpers, put a town on their map of New York that didn't exist.

  • Mapmakers used trap streets in 1920s to catch map copiers
  • TrapR tool uses markers, canaries, fingerprints to detect code copiers
  • Multi-layered approach helps monitor and protect code in Git repositories

Short Stints & Contract Hops: Framing a Choppy Timeline

The resume that worries people most in this series is not the one with a gap. It is the one with too many entries. Eight months at a startup that ran out of money.

  • Multiple short stints at startups and contracts create choppy timeline
  • Normalize dates using consistent format for ATS parsing
  • Group contract work under one umbrella entry with neutral reason

Capacitor vs No-Code Wrappers: Shipping Your Web App to iOS and Android in 2026

You have a web app. Users keep asking for "the app". Rewriting everything in Swift and Kotlin is out of the question. So you wrap it.

  • Capacitor requires manual setup and native feature integration
  • No-code wrappers like Glideep provide quick, cost-effective app deployment
  • Both methods face app review challenges, requiring native navigation and offline screens

More from Saturday 21 November →