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);
$a = [3, 1, 2];
$unique = array_unique($a, SORT_REGULAR | SORT_NUMERIC);
Why is it reported? #
The $flags parameter of array_unique() accepts a single sorting constant, not a bitmask of combined constants. Combining SORT_REGULAR | SORT_NUMERIC with the | operator produces an integer value that does not correspond to any valid flag, leading to unexpected behavior.
Some PHP functions accept bitmask parameters where multiple flags can be combined (like json_encode()), while others expect exactly one constant value. PHPStan knows which parameters allow bitmasks and which do not.
This check is only performed on PHP 8.0+.
How to fix it #
Pass a single constant without combining:
$a = [3, 1, 2];
-$unique = array_unique($a, SORT_REGULAR | SORT_NUMERIC);
+$unique = array_unique($a, SORT_NUMERIC);
How to ignore this error #
You can use the identifier argument.bitmaskNotAllowed to ignore this error using a comment:
// @phpstan-ignore argument.bitmaskNotAllowed
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: argument.bitmaskNotAllowed
Rules that report this error #
- PHPStan\Rules\Classes\ClassAttributesRule [1]
- PHPStan\Rules\Classes\ClassConstantAttributesRule [1]
- PHPStan\Rules\Classes\InstantiationRule [1]
- PHPStan\Rules\Constants\ConstantAttributesRule [1]
- PHPStan\Rules\EnumCases\EnumCaseAttributesRule [1]
- PHPStan\Rules\Functions\ArrowFunctionAttributesRule [1]
- PHPStan\Rules\Functions\CallCallablesRule [1]
- PHPStan\Rules\Functions\CallToFunctionParametersRule [1]
- PHPStan\Rules\Functions\CallUserFuncRule [1]
- PHPStan\Rules\Functions\ClosureAttributesRule [1]
- PHPStan\Rules\Functions\FunctionAttributesRule [1]
- PHPStan\Rules\Functions\ParamAttributesRule [1]
- PHPStan\Rules\Methods\CallMethodsRule [1]
- PHPStan\Rules\Methods\CallStaticMethodsRule [1]
- PHPStan\Rules\Methods\MethodAttributesRule [1]
- PHPStan\Rules\Properties\PropertyAttributesRule [1]
- PHPStan\Rules\Properties\PropertyHookAttributesRule [1]
- PHPStan\Rules\Traits\TraitAttributesRule [1]