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

PHP 8 — Key Features

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

Closest to 'only careful code review or runtime testing' (d7). The detection_hints.tools field is empty. The common mistakes span multiple categories: UnhandledMatchError only surfaces at runtime when a non-covered value hits a match expression; readonly-but-mutable object confusion is invisible until a bug manifests; dynamic property removal is a deprecation/error that surfaces only at runtime on PHP 8.2+. No single linter catches all of these automatically, so d7 is the right anchor.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix mentions Rector with PHP80/81/82 sets, which automates many patterns. However, Rector handles common cases — manual review is still needed for match exhaustiveness, readonly property semantics, and dynamic property declarations across the codebase. This is more than a one-line fix but less than full architectural rework, landing at e5.

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

Closest to 'persistent productivity tax' (b5). The applies_to covers both web and cli contexts broadly. Misunderstandings (e.g. JIT expectations, readonly semantics) create an ongoing cognitive tax for maintainers who interact with PHP 8 features regularly. The burden is not codebase-defining but does slow down multiple work streams when teams hold incorrect mental models about JIT, readonly, or match exhaustiveness.

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

Closest to 'notable trap — a documented gotcha most devs eventually learn' (t5). The canonical misconception is that JIT makes all PHP code faster, when in reality typical I/O-bound web apps see negligible benefit. Additionally, readonly-as-immutable is a well-documented but frequently encountered confusion. These are documented gotchas that most PHP developers encounter, matching t5 well.

About DEBT scoring →

Also Known As

PHP 8 PHP8 PHP 8.0 PHP 8.1 PHP 8.2 PHP 8.3 PHP 8.4 modern PHP

TL;DR

PHP 8.0–8.4 introduced match expressions, named arguments, union types, nullsafe operator, fibers, enums, readonly properties, first-class callables, and a JIT compiler — the most significant evolution of the language since PHP 5.

Explanation

PHP 8.0 (2020): named arguments, union types, match expression (strict, no fall-through, returns a value), nullsafe operator (?->), JIT compiler, constructor property promotion, str_contains/str_starts_with/str_ends_with, throw as expression, attributes. PHP 8.1 (2021): enums, readonly properties, fibers, intersection types, never return type, array_is_list(), first-class callable syntax (strlen(...)), new in initializers. PHP 8.2 (2022): readonly classes, disjunctive normal form (DNF) types, deprecated dynamic properties, true/false/null standalone types. PHP 8.3 (2023): typed class constants, json_validate(), Override attribute, deep-cloning of readonly properties. PHP 8.4 (2024): property hooks, asymmetric visibility (public get / protected set), updated array functions (array_find, array_any, array_all), HTML5 parser for DOM extension.

Common Misconception

PHP 8's JIT compiler makes all PHP code significantly faster. The JIT primarily benefits CPU-bound code like mathematical computations, image processing, and scientific calculations. Typical web applications are I/O-bound — most time is spent waiting for database queries, HTTP calls, and file reads — and see negligible JIT speedup. The more impactful PHP 8 performance improvement is OPcache improvements and the overall engine optimisations, not the JIT itself.

Why It Matters

PHP 8 is not a minor version bump — it introduces language features that fundamentally change how clean PHP code is written. Match expressions eliminate fall-through bugs from switch. Named arguments make function calls self-documenting and allow skipping optional parameters. Constructor promotion halves the boilerplate for value objects. Enums replace fragile string/integer constants with type-safe objects. Fibers enable async frameworks without callbacks. PHP 7 codebases miss all of these, and the upgrade path is well-documented with automated migration tooling (Rector).

Common Mistakes

  • Using match without covering all cases — match throws UnhandledMatchError if no arm matches and there is no default; always include a default arm or ensure exhaustive coverage.
  • Confusing readonly properties with immutable objects — readonly prevents reassignment after initialisation but does not deep-clone objects; a readonly property holding an object can still have its object's properties mutated.
  • Using dynamic properties removed in PHP 8.2 — assigning to undeclared properties throws a deprecation in 8.1 and an error in 8.2; declare all properties explicitly.
  • Expecting JIT to speed up database-heavy web requests — benchmark before enabling JIT; the overhead of JIT compilation can slow simple scripts.

Code Examples

✗ Vulnerable
// PHP 7 style — verbose, error-prone
function createUser(string $name, ?string $email = null, int $role = 0): User {
    $this->name  = $name;
    $this->email = $email;
    $this->role  = $role;
}

$status = 'active';
$label = $status === 'active' ? 'Active' : ($status === 'pending' ? 'Pending' : 'Unknown');
✓ Fixed
// PHP 8 style — concise, type-safe
enum Status { case Active; case Pending; case Suspended; }

class User {
    public function __construct(
        public readonly string  $name,
        public readonly ?string $email = null,
        public readonly Status  $status = Status::Active,
    ) {}
}

$label = match($status) {
    Status::Active  => 'Active',
    Status::Pending => 'Pending',
    default         => 'Unknown',
};

Added 23 Mar 2026
Edited 4 Apr 2026
Views 49
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 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 2 pings F 2 pings S 2 pings S 2 pings M 2 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 10 Amazonbot 7 Google 4 Perplexity 4 Ahrefs 3 SEMrush 3 Meta AI 2 Claude 2 Bing 2 ChatGPT 1 Sogou 1 PetalBot 1
crawler 37 crawler_json 3
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Run Rector with the PHP80/PHP81/PHP82 sets to automatically migrate PHP 7 code to modern PHP 8 equivalents — handles most common patterns automatically
📦 Applies To
PHP 8.0+ web cli


✓ schema.org compliant