Parameter $%s of %s hook %s::$%s must not have a default value¶
Description¶
The parameter of a set property hook cannot declare a default value. The hook is always invoked with the value being assigned to the property, so a default value would never actually be used, and PHP rejects it as meaningless.
Example¶
<?php
class X
{
public string $property {
set(string $value = 'default') {
$this->property = $value;
}
}
}
?>
Literal Examples¶
Parameter $value of set hook X::$property must not have a default value
Solutions¶
Remove the default value from the hook’s parameter.
If a fallback value is needed, assign a default to the property itself, or handle it inside the hook’s body.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.