Learning how to spot BC breaks before a migration
Explore methods to detect backwards compatibility (BC) breaks in PHP code prior to migration to PHP 8. Understand how to create automated BC break scanners with configuration files, detect common issues such as resource-to-object changes, removed functions, and magic method violations, and learn to handle complex break cases via callbacks.
Ideally, we should go into the PHP 8 migration with an action plan in hand. A critical part of this action plan includes getting an idea of how many potential BC (backwards-compatability) breaks exist in our current code base. We show how to develop a BC break sniffer that automates the process of looking through hundreds of code files for potential BC breaks.
As we know about BC issues that might arise in PHP 8.
An overview of BC breaks
We already know, having read the previous chapters in this course, that potential code breaks originate from several sources. Let’s briefly summarize the general trends that might lead to code failure after a migration since we are familiar with these topics.
Resource-to-object migration
Minimum versions for supporting OS libraries
IteratortoIteratorAggregatemigrationRemoved functions
Usage changes
Magic method signature enforcement
Many of the changes can be detected by adding a simple callback based upon preg_match() or strpos(). Usage changes are much more difficult to detect because, at a glance, there’s no way for an automated break scanner to detect the result of usage ...