← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Migrating from PHP 5.x to PHP 7 and 8

PHP PHP 5.0+ Intermediate
debt(d3/e5/b5/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

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.

e5 Effort Remediation debt — work required to fix once spotted

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.

b5 Burden Structural debt — long-term weight of choosing wrong

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.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

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.

About DEBT scoring →

Also Known As

PHP 5 to 7 migration PHP upgrade PHP 7 compatibility

TL;DR

PHP 7 removed mysql_*, ereg functions, and several deprecated features — a systematic approach using Rector and PHPCompatibility catches 95% of issues automatically.

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

Migrating from PHP 5.6 to 7 requires rewriting your application — most migrations are mechanical find-and-replace operations that Rector can automate.

Why It Matters

PHP 5.6 reached EOL in December 2018 — any production server still on PHP 5 has years of unpatched vulnerabilities. Migration is urgent.

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

✗ Vulnerable
// 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
✓ Fixed
// 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

Added 22 Mar 2026
Edited 23 Mar 2026
Views 37
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S 1 ping S 0 pings M 1 ping T 2 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 2 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 Scrapy 5 Google 4 Ahrefs 3 ChatGPT 3 Meta AI 2 Perplexity 2 SEMrush 2 Claude 1 Bing 1
crawler 29 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🔴 Critical ⚙ Fix effort: High
⚡ Quick Fix
Run composer require --dev rector/rector, create rector.php targeting PHP_80, then run vendor/bin/rector process src/ and fix remaining issues manually
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
mysql_connect() mysql_query(); ereg() eregi(); call-time pass-by-reference &$param in call sites
Auto-detectable: ✓ Yes rector phpcs phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Medium Context: File Tests: Update


✓ schema.org compliant