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

PHP 8 — Key Features

php PHP 8.0+ Intermediate

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 21
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
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 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping 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 6 Perplexity 4 Google 2 ChatGPT 1 Meta AI 1 Ahrefs 1
crawler 15
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