Migrating from PHP 5.x to PHP 7 and 8
debt(d3/e5/b5/t5)
Closest to 'default linter catches the common case' (d3). The detection_hints list Rector, PHPCS, and PHPStan as tools that catch deprecated function usage (mysql_*, ereg*, etc.) with automated detection. These are standard PHP ecosystem tools that flag PHP 5 compatibility issues reliably, though they require explicit configuration for migration checks.
Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix suggests running Rector to automate most changes, but the scope is 'src/' — the entire codebase. While individual fixes are mechanical (mysql_* → PDO, ereg → preg), the migration touches many files and requires manual cleanup after automation, plus third-party package compatibility verification as noted in common_mistakes.
Closest to 'persistent productivity tax' (b5). The applies_to shows this affects all PHP contexts (web, cli, queue-worker). While the migration itself is a one-time event, delaying it creates ongoing burden: teams must maintain PHP 5 compatibility, can't use modern features, and carry security debt. The choice to stay on PHP 5 imposes a tax on every developer who wants to use newer PHP features or packages.
Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception field states developers wrongly believe migration requires rewriting the application, when most changes are mechanical. Common_mistakes reveal the real trap: assuming migration is either trivial (skipping tests, ignoring third-party packages) or insurmountable (ignoring Rector automation). The expectation mismatch causes both over-engineering and under-preparation.
Also Known As
TL;DR
Explanation
Migrating from PHP 5.x to 7/8 involves several categories. Removed: mysql_* extension, ereg_* functions, magic_quotes_gpc, safe_mode, call-time pass-by-reference, and mcrypt. Changed: strict comparison semantics (0 == 'string' is now false in PHP 7), error handling (many fatals become catchable Errors), constructor-style constructors. Tools: Rector auto-fixes most mechanical changes, phpcs with PHPCompatibility standard flags version-specific issues. Running tests on a PHP 7 Docker container before deploying is the safest approach.
Common Misconception
Why It Matters
Common Mistakes
- Not running the full test suite on PHP 7 before deploying
- Ignoring Rector in favour of manual migration
- Not checking third-party packages for PHP 7 compatibility
- Leaving mysql_* calls for later and being surprised by fatal errors in production
Code Examples
// PHP 5 patterns that break in PHP 7:
ereg('^[a-z]+$', $input); // Fatal — ereg removed
mysql_query($sql); // Fatal — mysql_ removed
list($a, $b) = $arr; // OK but some list() behaviour changed
// PHP 7 equivalents:
preg_match('/^[a-z]+$/', $input);
$pdo->prepare($sql)->execute();
[$a, $b] = $arr; // Short list syntax
// Run Rector before upgrading:
// vendor/bin/rector process --dry-run