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

Migrating from PHP 5.x to PHP 7 and 8

php PHP 5.0+ Intermediate

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 18
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Amazonbot 8 Perplexity 2 Google 2 Meta AI 1 Ahrefs 1
crawler 12 crawler_json 1 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