WNWEBSNEXUS

PHP & WordPress

How to Upgrade an Old PHP 5 or PHP 7 Application to PHP 8.4

Upgrading PHP sounds like a server setting, and for well-maintained code it nearly is. For an application written in the PHP 5 or early PHP 7 era, though, the jump to PHP 8 removes functions, changes how errors behave and breaks old libraries. With PHP 8.1 and older now outside support and exposed to PHP2Shell, many businesses have to make this jump quickly. This is the process we use at WebsNexus to do it safely.

By WebsNexus · October 25, 2026 · 4 min read · Updated October 25, 2026

Common breaking changes when upgrading to PHP 8

Old codeWhat happens on PHP 8Fix
mysql_* functionsRemoved since PHP 7.0Rewrite with PDO or mysqli and prepared statements
each(), create_function()RemovedReplace with foreach and closures
Curly-brace string offsets ($s{0})Fatal errorUse $s[0]
Loose string-number comparisonsDifferent results (0 == "abc" is now false)Review comparisons; use strict checks
Warnings treated as harmlessMany are now TypeError or ValueError exceptionsValidate inputs; handle exceptions
Dynamic propertiesDeprecated since 8.2Declare properties or use #[AllowDynamicProperties]
Old framework versionsUnsupported on PHP 8Upgrade framework step by step

Step 1: get the code under control

Put the full application in Git if it is not already, including configuration templates but not secrets. Create a staging server that matches production, with a copy of the database. Record the current PHP version, extensions and php.ini settings. Many legacy upgrades fail not on the code but on a missing extension or a setting someone changed years ago.

Step 2: add a safety net of tests

Old applications rarely have tests, and writing a full suite is not realistic. Instead, write end-to-end tests for the journeys that make money or cause pain if they break: login, sign-up, checkout or payment, the main forms, key reports and admin actions. Tools such as Playwright can drive the real application in a browser. These tests tell you whether the upgraded application still works.

Step 3: let tools do the bulk of the work

Run PHPStan or Psalm to find type errors and calls to removed functions, and PHPCompatibility to flag code incompatible with the target version. Then use Rector, which automatically rewrites code for newer PHP versions: it can convert removed constructs, add type declarations and apply framework upgrade rules. Review its changes like any other code change. On typical legacy code, tools handle a large share of the mechanical fixes, leaving people to deal with the logic.

Step 4: upgrade dependencies and the framework

Update Composer packages to versions that support PHP 8.4. If the application uses a framework, upgrade it one major version at a time, following each version’s upgrade guide; skipping versions multiplies the risk. Replace abandoned libraries with maintained ones. If there is no Composer and libraries were copied into the code by hand, this step takes longest and is where you learn whether an upgrade is realistic.

Step 5: test on the new version and switch

Run the application on PHP 8.4 or 8.5 in staging with error logging set to report everything, including deprecations, and work through the log. Run the end-to-end tests, then ask real users to try the staging version. Switch production during a quiet period with a rollback plan, and watch the error log closely for the first week.

When to migrate instead of upgrading

If the audit shows most files need changes, there is no framework, business logic is tangled into HTML templates and the database layer must be rewritten anyway, you are effectively rewriting the application in PHP. At that point, compare the upgrade quote with a phased migration to Node.js, Next.js or Python, which leaves you with modern architecture and long-term support rather than old code on a new version.

WebsNexus does both and quotes both. PHP upgrades and modernization start from $130 per day after a short audit. Message us on WhatsApp at +92 326 6379003.

Frequently asked questions

How long does it take to upgrade from PHP 7 to PHP 8?

For a framework-based PHP 7 application with Composer, usually a few days to a few weeks. Custom PHP 5-era applications without tests or Composer can take much longer.

What breaks when upgrading to PHP 8?

Removed functions such as mysql_* and each(), stricter type handling that turns warnings into exceptions, changed string-number comparisons, deprecated dynamic properties and old framework or library versions.

What is Rector?

Rector is an open-source tool that automatically refactors PHP code, including upgrading it to newer PHP versions and applying framework upgrade rules. Its changes still need review and testing.

Should I upgrade to PHP 8.4 or 8.5?

Either is a good target in October 2026. PHP 8.5 has the longest support, to the end of 2029; PHP 8.4 is supported to the end of 2028 and may be better supported by older libraries.

Is it cheaper to upgrade or rewrite a PHP app?

Upgrading is cheaper when the code is reasonably structured. When most of the code must change anyway, a phased migration to a modern stack often costs similar and delivers more.

Sources

What now

Ready to move offold PHP?

We migrate PHP and WordPress applications to Node.js, Next.js, Python and Django in phases, keeping your data, URLs and rankings. Start with a short audit and a fixed plan.