What's new

What`s new?!

PHP

Last updated: March 15, 2025 at 12:00 AM

PHP

Old school PHP, the language most of us used and still not dead!

PHP language main features on each release are listed below, click on each version title to see the features.

PHP 8.5 (Upcoming, 2025)

(To be announced)


PHP 8.4 (2024)

Property Hooks

Allows dynamic getters and setters

class User {
    public string $name;
    public function __get(string $name) {}
}

Asymmetric Visibility in Classes

Different getter/setter visibility

class Example {
    public function __construct(
        public string $name
    ) {}
}

Database Driver-Specific PDO Classes

Enhances database-specific functionality

$pdo = new MySQLiPDO("mysql:host=localhost;dbname=test");

Lazy Objects

Improve memory performance by delaying initialization

$object = LazyObject::create(Foo::class);

PHP 8.3 (2023)

Typed Class Constants

Allows type hints for class constants

class A {
    public const int VALUE = 10;
}

json_validate Function

Validate JSON without decoding

json_validate('{"key": "value"}');

Granular DateTime Exceptions

More specific DateTime-related exceptions

try {
    new DateTime("invalid");
} catch (DateMalformedStringException $e) {
    echo "Invalid date";
}

PHP 8.2 (2022)

Disjunctive Normal Form (DNF) Types

Combine types using OR

function test((A&B)|C $x) {}

Readonly Classes

Make entire class readonly

readonly class User {
    public string $name;
}

True, False, Null Types

Allows specifying these as standalone types

function example(true $flag) {}

Sensitive Parameter Redaction

Redact parameters from stack traces

function login(#[\SensitiveParameter] string $password) {}

New Random Extension

Better random number generation

$rand = new Random\Engine\Secure();

PHP 8.1 (2021)

Enumerations (Enums)

Define a set of possible values

enum Status {
    case Pending;
    case Approved;
}

Readonly Properties

Prevents property modification

class User {
    public readonly string $name;
}

Fibers

Allows cooperative multitasking

$fiber = new Fiber(function () {
    echo "Inside Fiber";
});
$fiber->start();

Intersection Types

Require a type to implement multiple interfaces

function process(A&B $value) {}

Never Return Type

Indicates a function never returns

function redirect(): never {
    exit;
}

PHP 8.0 (2020)

Named Arguments

Pass arguments by name

function test($a, $b) {}
test(b: 2, a: 1);

Match Expression

Switch alternative with strict comparison

$result = match($x) {
    1 => 'one',
    2 => 'two',
    default => 'other',
};

Just-In-Time Compilation (JIT)

Improves PHP performance at runtime

// Enabled via php.ini: opcache.jit=1235

Constructor Property Promotion

Simplifies constructor property initialization

class User {
    public function __construct(private string $name) {}
}

Union Types

Allows multiple types for parameters and return values

function example(int|string $value) {}

PHP 7.4 (2019)

Typed Properties

Allows type hints for class properties

class User {
    public int $id;
}

Arrow Functions

Shorter syntax for anonymous functions

$add = fn($a, $b) => $a + $b;

Underscore Numeric Separator

Improves readability of large numbers

$number = 1_000_000;

PHP 7.3 (2018)

Trailing Commas in Function Calls

Allows trailing commas in function calls

function test($a, $b,) {}

JSON_THROW_ON_ERROR

Throws exception on JSON errors

json_decode("invalid", false, 512, JSON_THROW_ON_ERROR);

Heredoc/Nowdoc Syntax Improvements

Allows better indentation handling

$str = <<<TEXT
    Indented text
TEXT;

PHP 7.2 (2017)

Object Type Hint

Allows specifying "object" as a type hint

function setObject(object $obj) {}

Argon2 Password Hashing

Stronger password hashing algorithm

$password = password_hash('secret', PASSWORD_ARGON2I);

Class Constant Visibility

Allows visibility modifiers for class constants

class MyClass {
    private const SECRET = 'hidden';
}

PHP 7.1 (2016)

Nullable Types

Allows null values in type hints

function setAge(?int $age) {}

Iterable Type Hint

Allows any iterable (arrays, Traversable)

function foo(iterable $items) {}

Void Return Type

Function must not return a value

function test(): void {
    echo "Hello";
}

PHP 7.0 (2015)

Scalar Type Declarations

Allows specifying parameter and return types

function add(int $a, int $b): int {
    return $a + $b;
}

Null Coalescing Operator (??)

Returns the first non-null operand

$username = $_GET['user'] ?? 'guest';

Spaceship Operator (<=>)

Three-way comparison

echo 2 <=> 3; // -1