How a PHP upgrade works overall, how big the step from your PHP version is and when the framework has to move too is covered in the article PHP upgrade. Within that process, the before-and-after comparison provides the proof that your application calculates and works the same way after the PHP upgrade as it did before.
Why is a PHP upgrade without tests risky?
A PHP upgrade without tests is risky because new PHP versions change the behavior of individual functions without the application crashing. Which functions are affected is listed in the migration notes on php.net for every version, for example for the move to PHP 8.4.
Errors that show up right away are the smaller problem in a PHP upgrade: someone reports a page with an error message on the first morning. The tricky part is silent deviations in amounts, rounding, date calculations or character counts that only become visible in an invoice, a billing run or an export.
In upgrade projects at Unique-P, one principle therefore applies: an application that “runs” after the PHP upgrade doesn’t necessarily calculate the same way. Only a comparison can prove that it does.
What is a before-and-after comparison?
A before-and-after comparison, also called a golden master or characterization test, records how an application behaves today and checks whether it behaves the same way after a change. It doesn’t ask whether a result is correct, but whether it has stayed the same. In a pure PHP upgrade, that is exactly the question.
A before-and-after comparison needs neither existing tests nor documentation. That makes it especially suitable for applications whose developer is no longer available. How to take over such an application as a whole is covered in the article taking over a PHP application without documentation.
How does a before-and-after comparison work in a PHP upgrade?
- The live version as the baseline. The before-and-after comparison starts with the code that runs live today, not with the state in the repository. If the two differ, for example because of fixes made directly on the server, the live version counts.
- A copy of the data in a separate test environment. The old and new versions run on the same copy of the data, separate from live operations. Emails go to a test mailbox, payments and outgoing interfaces are blocked, and the data location and the client’s consent are settled beforehand.
- Old and new versions side by side. The old version runs on the previous PHP version, the new one on the target version. Everything else stays the same: libraries, configuration, time zone and data.
- Comparison on several levels. A script calls the same functions, pages and workflows in both versions and compares the results, from individual calculated values to the finished invoice as a PDF.
- Filter out the noise. Timestamps, sequential numbers and technical IDs differ on every run. So that they don’t hide real deviations, the comparison filters them out. Two runs of the old version show what normal noise looks like.
- Cross-check. A before-and-after comparison is only worth something if it can find errors. Without the code adjustments, it has to raise an alarm on the new PHP version. If it stays silent, it isn’t checking enough.
- Business sign-off. The business department checks what only it can judge: amounts against real documents, and workflows with external systems that are blocked in the test environment.
What belongs in a before-and-after comparison?
| Level | What is compared | What to watch for |
|---|---|---|
| Calculations | Amounts, VAT, rounding and discounts with many input values, including edge cases | Rounding and floating-point numbers are the first to react to a new PHP version |
| Pages and downloads | Every URL for every user role: status code and content | Filter out timestamps and session data |
| Documents | Invoices, quotes, PDF and Excel exports | Filter out creation dates and technical IDs |
| Write operations | Creating an order, generating an invoice, changing a status: the entries in the database | Normalize timestamps and ordering |
| Emails | Recipients, subject and body | Send only to the test mailbox |
| Interfaces | Requests to and responses from external systems | Usually blocked in the test environment, so part of the business review |
Pure PHP upgrade or modernize right away?
A pure PHP upgrade changes only what the new PHP version requires: all libraries keep their version, features stay the same, and known bugs are deliberately left in place. Every additional change brings another round of comparisons and business tests.
A pure PHP upgrade is especially worthwhile if the application will soon be replaced or keeps running as an archive. Improvements and bug fixes come afterward as a separate stage, with their own comparison. Which effort is still worth it before a replacement is covered in the article legacy system until replacement.
Which target version fits depends on the deadlines: according to php.net, PHP 8.2 gets security updates only until December 31, 2026, and PHP 8.4 until December 31, 2028. All dates are in the article PHP end of life.
How does the PHP upgrade go live without customers noticing?
- New version next to the old one. The new version is ready on the server before the switch. The old version stays in place next to it, unchanged.
- Fresh backup. The database is backed up right before switching to the new PHP version.
- Switch in stages. First the PHP version and the code change, then every further change follows on its own, such as new restrictions in the server configuration. The same checks run after each stage.
- A way back in minutes. If the database fits both versions, a prepared rollback returns to the old version within a few minutes. The way back stays open until the new version has had a few quiet days.
Where does the experience in this article come from?
The experience in this article comes from upgrade and takeover projects by Unique-P with PHP applications whose developer was no longer available. Names, figures and details of individual clients are deliberately left out: confidentiality is part of working on other people’s applications.
How big the PHP upgrade will be for your application and which checks it needs is clarified by the Takeover Assessment from Unique-P within 5 business days of full access.
Sources
- [1]Supported Versions · php.net
- [2]Migrating from PHP 8.3.x to PHP 8.4.x · php.net
- [3]Characterization test · Wikipedia