Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
final class User
{
public string $name {
/**
* @pure-unless-parameter-passed $value
*/
set {
$this->name = $value;
}
}
}
Why is it reported? #
The @pure-unless-parameter-passed tag marks a function as pure unless an argument is passed for the named optional by-reference parameter, like the $count parameter of str_replace().
The $value parameter of a set property hook (PHP 8.4+) always receives the assigned value — it can never be omitted. The condition under which the hook would be pure can never be met, so the tag has no meaning here. This mirrors pureMethod.nonOptionalParameterPassed for regular methods.
The same tag also triggers purePropertyHook.parameterPassedNotByRef, because $value is passed by value.
How to fix it #
Remove the tag. A property hook cannot have an optional out-parameter, so @pure-unless-parameter-passed never applies to it:
public string $name {
- /**
- * @pure-unless-parameter-passed $value
- */
set {
$this->name = $value;
}
}
How to ignore this error #
You can use the identifier purePropertyHook.nonOptionalParameterPassed to ignore this error using a comment:
// @phpstan-ignore purePropertyHook.nonOptionalParameterPassed
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: purePropertyHook.nonOptionalParameterPassed