no-unset-hookable-property
What it does
Section titled “What it does”Reports unset($this->name) of a property the class declares when a subclass could give the property a hook (PHP 8.4): the class is not final and the property is not private, final, static or readonly.
Why it matters
Section titled “Why it matters”A property with a hook cannot be unset, so the call fails with an error in the subclass that overrides the property, while it works in the class that wrote it.
To fix, set the property to null instead, or make the class or the property final.
Example
Section titled “Example”<?phpclass A { public $a; private $b; public readonly int $c; function f() { unset($this->a); unset($this->b); unset($this->c); unset($this->z); }}final class B { public $a; function f() { unset($this->a); } }Configuration
Section titled “Configuration”php: lint: rules: no-unset-hookable-property: warn # off (default), warn, errorEnabled by the presets: php/phpstan.
Suppress one line with sudsy-disable-next-line no-unset-hookable-property in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| phpstan | unset.possiblyHookedProperty |
partial | unset($this->p) of a property the class declares; a property declared in a parent in another file is not seen. |