Differences Between PHP Versions

PHP has evolved rapidly through its 8.x series. Each release introduces new language features, performance gains, and deprecations that affect how modern PHP applications are written. This guide covers the key differences between PHP 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5.

PHP 8.0

Released: 26 November 2020  ·  End of Life: 26 November 2023

PHP 8.0 was a landmark release that introduced the JIT compiler, union types, named arguments, and the match expression — fundamentally modernising the language and setting the foundation for the entire 8.x series. It is now end-of-life.

JIT Compiler

The Just-In-Time compiler compiles PHP bytecode to native machine code at runtime, delivering significant performance improvements for CPU-intensive workloads. While web applications see modest gains, long-running scripts and mathematical computations benefit the most.

Named Arguments

Named arguments allow passing values to a function by parameter name rather than position, making calls with many optional parameters far more readable and less error-prone.

// Before PHP 8.0
array_slice($array, 0, null, true);

// PHP 8.0
array_slice($array, offset: 0, preserve_keys: true);
PHP

Union Types

Parameters, return values, and properties can now declare multiple accepted types using the pipe (|) syntax, replacing the need for docblock-only type hints.

function formatId(int|string $id): string {
    return (string) $id;
}
PHP

Match Expression

The match expression is a stricter, expression-based alternative to switch. It uses strict comparison, returns a value, and throws an UnhandledMatchError if no arm matches.

$label = match($status) {
    1 => 'Active',
    2 => 'Inactive',
    default => 'Unknown',
};
PHP

Nullsafe Operator

The ?-> operator short-circuits a method or property chain when a null is encountered, eliminating deeply nested null checks.

$city = $user?->getAddress()?->getCity();
PHP

Constructor Property Promotion

Properties can be declared and assigned directly in the constructor signature, drastically reducing boilerplate for simple value objects.

class Point {
    public function __construct(
        public float $x,
        public float $y,
        public float $z,
    ) {}
}
PHP

Notable Deprecations

  • Many previously silenced warnings were promoted to proper errors (e.g., accessing undefined variables).
  • The create_function() function was removed.
  • The each() function was removed.

PHP 8.1

Released: 25 November 2021  ·  End of Life: 31 December 2024

PHP 8.1 brought a significant set of language improvements focused on expressiveness and type safety. It is now end-of-life and upgrading to a newer branch is strongly recommended.

Enumerations (Enums)

Native enum support was one of the most anticipated additions. Enums allow developers to define a fixed set of named values, replacing fragile class constants or string-based patterns.

enum Status {
    case Active;
    case Inactive;
    case Pending;
}

$current = Status::Active;
PHP

Backed enums can also carry a scalar value (string or int), making them suitable for database storage and serialization.

Fibers

Fibers introduced a low-level concurrency primitive to PHP. They allow a function to pause its own execution and resume later, enabling cooperative multitasking without threads. Async frameworks like ReactPHP and Amp adopted Fibers as a foundation for their coroutine models.

Readonly Properties

Class properties can now be declared readonly, meaning they can only be assigned once — typically in the constructor. This enforces immutability without requiring custom getter logic.

class User {
    public function __construct(
        public readonly int $id,
        public readonly string $name,
    ) {}
}
PHP

Intersection Types

Intersection types allow a parameter or return value to satisfy multiple interfaces simultaneously. For example, Countable&Iterator requires an object that implements both.

never Return Type

The never return type signals that a function will never return normally — it always throws an exception or calls exit(). This helps static analysis tools reason about control flow.

Array Unpacking with String Keys

The spread operator (...) can now be used with string-keyed arrays, not just numeric ones, making array merging more flexible.

Notable Deprecations

  • Passing null to non-nullable internal function parameters now triggers a deprecation notice.
  • The mysqli_get_client_info() function was deprecated.
  • Implicit float-to-int conversions that lose precision now emit a deprecation warning.

PHP 8.2

Released: 8 December 2022  ·  Security Support Until: 31 December 2025

PHP 8.2 refined the type system further and introduced readonly classes, while also cleaning up several long-standing inconsistencies in the language.

Readonly Classes

Building on PHP 8.1's readonly properties, PHP 8.2 allows marking an entire class as readonly. All promoted and declared properties automatically become readonly, reducing boilerplate for value objects and DTOs.

readonly class Point {
    public function __construct(
        public float $x,
        public float $y,
        public float $z,
    ) {}
}
PHP

Disjunctive Normal Form (DNF) Types

DNF types allow combining union types and intersection types in a single declaration. For example, (Countable&Iterator)|null is now valid, giving developers precise control over complex type constraints.

true, false, and null as Standalone Types

true, false, and null can now be used as standalone return types, not just as part of a union. This is useful for functions that always return a literal boolean or null.

Fibers Improvements & Constants in Traits

Traits can now define constants, which was previously not allowed. This enables traits to carry related constant values alongside their methods without requiring a separate interface or abstract class.

Notable Deprecations

  • Dynamic properties (setting undefined properties on objects) are deprecated and will throw an error in PHP 9. Use #[AllowDynamicProperties] to opt in.
  • Partially supported callables (e.g., "self::method" as a string) are deprecated.
  • The ${var} and ${expr} string interpolation forms are deprecated in favour of {$var}.

PHP 8.3

Released: 23 November 2023  ·  Active Support Until: 31 December 2025  ·  Security Support Until: 31 December 2026

PHP 8.3 focused on quality-of-life improvements: typed class constants, more granular JSON error handling, and several smaller ergonomic additions that reduce common boilerplate.

Typed Class Constants

Class, interface, and trait constants can now carry an explicit type declaration. This prevents accidental type mismatches when constants are overridden in child classes.

class Config {
    const string VERSION = '1.0.0';
    const int MAX_RETRIES = 3;
}
PHP

json_validate()

A new json_validate() function checks whether a string is valid JSON without fully decoding it. This is more memory-efficient than calling json_decode() and checking for errors when you only need to validate.

Dynamic Class Constant Fetch

Constants can now be accessed using a variable class or constant name, making dynamic dispatch patterns cleaner.

$class = 'Config';
$const = 'VERSION';
echo $class::$$const; // equivalent to Config::VERSION
PHP

Readonly Property Amendments

PHP 8.3 allows readonly properties to be re-initialised during cloning via __clone(), which was previously impossible. This makes immutable value objects easier to work with when you need a modified copy.

New Array Functions

  • array_find() — returns the first element matching a callback.
  • array_find_key() — returns the key of the first matching element.
  • array_any() — returns true if any element satisfies the callback.
  • array_all() — returns true if all elements satisfy the callback.

Notable Deprecations

  • Calling mt_rand() without arguments is deprecated.
  • The ReflectionProperty::setValue() signature without an object argument is deprecated.
  • Several ldap_* functions deprecated in favour of OOP alternatives.

PHP 8.4

Released: 21 November 2024  ·  Active Support Until: 31 December 2026  ·  Security Support Until: 31 December 2027

PHP 8.4 is the current stable release. It delivers property hooks, asymmetric visibility, a new HTML5-compliant parser, and a range of smaller improvements that modernise the language further.

Property Hooks

Property hooks allow get and set logic to be defined directly on a property declaration, eliminating the need for separate getter and setter methods in many cases.

class Temperature {
    public float $celsius {
        get => $this->celsius;
        set(float $value) {
            if ($value < -273.15) {
                throw new \ValueError('Temperature below absolute zero.');
            }
            $this->celsius = $value;
        }
    }
}
PHP

Asymmetric Visibility

Properties can now have different visibility for reading and writing. A property can be publicly readable but only writable from within the class or a subclass.

class Order {
    public private(set) int $status = 0;

    public function approve(): void {
        $this->status = 1; // allowed inside the class
    }
}

$order = new Order();
echo $order->status; // readable from outside
// $order->status = 2; // TypeError — not writable from outside
PHP

New HTML5 Parser (DOM Extension)

PHP 8.4 ships a new Dom\HTMLDocument class backed by the Lexbor HTML5 parser. Unlike the old DOMDocument, it correctly handles modern HTML5 markup, including void elements and optional closing tags, without generating spurious warnings.

Lazy Objects

The reflection API now supports creating lazy proxy and ghost objects. These are objects whose initialisation is deferred until a property is first accessed, which is useful for dependency injection containers and ORM lazy-loading without requiring third-party code generation.

New Array and String Functions

  • array_find(), array_find_key(), array_any(), array_all() — functional-style array helpers.
  • mb_trim(), mb_ltrim(), mb_rtrim() — multibyte-aware trimming functions.
  • mb_ucfirst(), mb_lcfirst() — multibyte capitalisation helpers.

Chaining new Without Parentheses

Method calls can now be chained directly on a new expression without wrapping it in parentheses.

// Before PHP 8.4
$result = (new Builder())->setOption('x')->build();

// PHP 8.4
$result = new Builder()->setOption('x')->build();
PHP

Notable Deprecations

  • Implicitly nullable parameter types (e.g., function foo(string $x = null)) are deprecated; use ?string explicitly.
  • The E_STRICT error level is deprecated.
  • Several LDAP and pgsql procedural functions deprecated in favour of OOP equivalents.

PHP 8.5

Released: 20 November 2025  ·  Active Support Until: 31 December 2027  ·  Security Support Until: 31 December 2028

PHP 8.5 is the latest stable release, continuing the annual November cadence. It brings pipe operator support, new array functions, improved error handling, and further refinements to the type system.

Pipe Operator

The |> pipe operator passes the result of the left-hand expression as the first argument to the callable on the right, enabling clean functional-style data transformation pipelines without deeply nested calls.

$result = $input
    |> trim(...)
    |> strtolower(...)
    |> htmlspecialchars(...);
PHP

array_first() and array_last()

Two new convenience functions retrieve the first or last element of an array without resetting the internal pointer or requiring a workaround like reset() / end().

$items = [3, 7, 12, 5];
echo array_first($items); // 3
echo array_last($items);  // 5
PHP

Closures in Constant Expressions

PHP 8.5 allows closures and arrow functions to appear in constant expressions, making it possible to define default parameter values and attribute arguments using inline callable logic.

Improved Error Handling

Several internal functions now throw proper typed exceptions instead of triggering warnings or returning false on failure, making error handling more consistent and easier to manage with standard try/catch blocks.

Notable Deprecations

  • Calling array_keys() with a search value but no strict flag is deprecated.
  • Several legacy date/time functions are deprecated in favour of the DateTime and DateTimeImmutable OOP API.

Quick Comparison

Feature 8.0 8.1 8.2 8.3 8.4 8.5
JIT Compiler
Named Arguments
Union Types
Enums
Fibers
Readonly Properties
Readonly Classes
DNF Types
Typed Class Constants
json_validate()
Property Hooks
Asymmetric Visibility
HTML5 DOM Parser
Lazy Objects
Pipe Operator
array_first() / array_last()

Explore PHP Functions

Browse our complete reference of PHP built-in functions with examples, edge cases, and common mistakes.

View All PHP Functions