PHP 8.4 Property Hooks: Simplify and Streamline Properties

Published on 2024-11-23


public int $postalCode {
    set {
        if (mb_strlen($value) !== 5) {
            throw new \InvalidArgumentException('Must be 5 characters.');
        }
        $this->postalCode = $value;
    }
}

Introducing Property Hooks in PHP 8.4 [...]

PHP 8.4 New Features: Discover What's New and Improved

Published on 2024-11-23


user@server:~$ php -v
PHP 8.4.1 (cli) (built: Nov 21 2024 14:54:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.1, Copyright (c) Zend Technologies
with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies
with Xdebug v3.4.0beta1, Copyright (c) 2002-2024, by Derick Rethans

[...]