PHP 8.4 introduces property hooks, one of the most significant additions to the language in years. Property hooks allow you to define get and set behaviors directly on class properties, eliminating the need for boilerplate getter/setter methods.
Here is a simple example:
class User {
public string $name {
set(string $value) {
$this->name = trim($value);
}
}
}This feature, combined with asymmetric visibility (public private(set)), makes PHP classes significantly more expressive and concise.
Comments
Admin March 1, 2025
PHPDev42 March 2, 2025
Admin March 3, 2025