PHP 8.4: Property Hooks, Asymmetric Visibility, and New Array Functions

PHP 8.4: Property Hooks, Asymmetric Visibility, and New Array Functions

PHP 8.4: Property Hooks, Asymmetric Visibility, and New Array Functions

PHP 8.4 has been officially released, bringing several highly anticipated language features that modernize how PHP developers write expressive object-oriented code.

Property Hooks

Property hooks let you attach get and set logic directly to a class property:

class User
{
    public string $fullName {
        get => $this->firstName . ' ' . $this->lastName;
    }

    public string $email {
        set(string $value) {
            $this->email = strtolower($value);
        }
    }
}

Asymmetric Visibility

Properties can now have different visibility for reading and writing:

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

New Array Functions

PHP 8.4 adds array_find(), array_find_key(), array_any(), and array_all() for more expressive array operations without needing array_filter workarounds.

All Comments