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

Migrating from PHP 7 to PHP 8

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

Closest to 'default linter catches' (d3). Rector, phpcs, and php-cs-fixer (all listed in detection_hints.tools) can identify deprecated functions like each() and create_function(), and Rector can automate many fixes. The automated:yes flag confirms tooling catches the common cases, though subtle type coercion changes may slip through.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor' (e5). The quick_fix mentions multiple categories of changes: running Rector, fixing type coercion issues, removing deprecated functions, and checking Composer dependencies. While individual fixes are small, a real migration touches many files across the codebase and requires extensive testing per the term's guidance.

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

Closest to 'persistent productivity tax' (b5). The migration applies across all PHP contexts (web, cli, queue-worker) per applies_to, affecting the entire codebase. While it's a one-time migration effort rather than ongoing decay, the choice of when to migrate shapes development velocity — staying on PHP 7 blocks new features and security patches, while migrating requires coordinated effort across all components.

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

Closest to 'notable trap / documented gotcha' (t5). The misconception field explicitly states developers wrongly assume 'PHP 7 code runs unchanged on PHP 8.' The why_it_matters section highlights silent behavioral changes like comparison operator associativity changes and match expressions throwing errors. These are documented gotchas that most PHP developers learn, but first-timers often discover through production bugs.

About DEBT scoring →

TL;DR

PHP 7→8 migration: fix type coercion changes (stricter), remove deprecated functions (each(), create_function()), update match/constructor promotion, check third-party compatibility.

Explanation

PHP 8.0 breaking changes from 7.x: (1) Arithmetic with non-numeric strings throws TypeError (no silent coercion). (2) match expression available (not breaking but replaces switch patterns). (3) each() removed — use foreach. (4) create_function() removed — use closures. (5) Deprecated @ error suppression changes. (6) PDO::FETCH_LAZY changed. PHP 8.1: (1) Passing null to non-nullable params deprecated. (2) Implicit float-int coercion emits deprecation. (3) Enums — not breaking but replace patterns. PHP 8.2: dynamic properties deprecated. Full list: php.net migration guides. Run php8-compat tool or Rector before upgrading.

Common Misconception

PHP 7 code runs unchanged on PHP 8 — stricter type handling and removed functions cause real breakage. Run rector and test extensively.

Why It Matters

PHP 8.0 introduced breaking changes that silently alter runtime behaviour without throwing errors — most dangerously, the change from left-associative to non-associative comparison operators, and match expressions that throw UnhandledMatchError instead of falling through like switch. Production apps migrated without a full test suite have shipped bugs that only surface under specific data conditions. Running php-cs-fixer and rector before going live is not optional.

Common Mistakes

  • Not running Rector before upgrading — misses automatable fixes.
  • Not testing with PHP 8's stricter type handling — silent 7.x bugs become errors.
  • Not checking Composer dependencies for PHP 8 compatibility before upgrading.

When To Use

  • When upgrading a PHP 7.x application to PHP 8.0 or later.
  • When security patches for PHP 7.4 end (November 2022) and moving to actively supported versions.
  • When you want access to PHP 8 features (match, enums, named arguments, constructor promotion).
  • Before deploying to hosting environments that only support PHP 8+.

Code Examples

✗ Vulnerable
// Breaks in PHP 8:
$result = '5 apples' + 3; // TypeError in 8 (was 8 in 7)
each($array); // Fatal — removed
✓ Fixed
// Before upgrading:
// 1. Run: composer check-platform-reqs
// 2. Run: vendor/bin/rector process --dry-run
// 3. Test with: php -d error_reporting=E_ALL index.php

// Fix arithmetic:
$count = (int)$str + 3;

// Fix each():
foreach ($array as $key => $value) { }

Added 23 Mar 2026
Edited 8 May 2026
Views 107
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 2 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 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 1 ping S 2 pings S 1 ping M 0 pings T 0 pings W 1 ping T 1 ping F 1 ping S
Amazonbot 1
Ahrefs 1
Scrapy 10 PetalBot 9 Amazonbot 8 Google 6 Ahrefs 6 SEMrush 6 Perplexity 4 Twitter/X 3 Brave Search 2 Applebot 2 Bing 2 ChatGPT 1 Unknown AI 1 Meta AI 1
crawler 60 pre-tracking 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
PHP php A server-side scripting language that generates web pages and APIs — the code runs on the server, and only its output (usually HTML or JSON) reaches the browser.

PHP is often the first server-side language people meet, and understanding its execution model — script starts fresh on every request, no memory between requests — explains most of how the web backend works: sessions, databases, and caching all exist to bridge that per-request amnesia.

💡 Start with PHP 8.x, declare(strict_types=1), and PDO — skip any tutorial that mentions mysql_query().

Ask Codex about PHP →
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: High
⚡ Quick Fix
Run Rector with PHP 8 migration rules. Fix type coercion (string+int now TypeError). Remove each()/create_function(). Check Composer deps for PHP 8 support.
📦 Applies To
PHP 7.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
each\(|create_function\(
Auto-detectable: ✓ Yes rector phpcs php-cs-fixer
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Medium Context: File Tests: Update


✓ schema.org compliant