What are Property Hooks (introduced in PHP 8.4), and what problem do they solve regarding getters and setters?
Last updated
Property Hooks (PHP 8.4) attach
getandsetlogic directly to a property declaration to compute, validate, or transform values.They replace
getX()/setX()boilerplate while callers keep plain$obj->propsyntax, so encapsulation doesn't change the public API.A hooked property can be virtual, meaning it has no backing storage (e.g. a computed full name).