Error Identifier: argument.unknownDefaultValue

← Back to argument.*

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);

$number = mt_rand(max: 5);

Why is it reported? #

Some built-in PHP functions and methods have optional parameters without a default value that PHP can use when the parameter is skipped. For example, mt_rand() accepts either no arguments or both $min and $max. There is no default value for $min.

When a named argument skips such a parameter, PHP throws an ArgumentCountError at runtime: mt_rand(): Argument #1 ($min) must be passed explicitly, because the default value is not known. The same applies to:

  • Named arguments that skip such a parameter in a direct call, e.g. array_keys($array, strict: true) skips $filter_value.
  • Calling a closure created from such a function, e.g. (mt_rand(...))(max: 5).
  • A partial function application (PHP 8.6+) where the variadic placeholder ... would leave such a parameter to its default, e.g. $reflectionProperty->setValue(?, ...).

How to fix it #

Pass the skipped argument explicitly:

 <?php declare(strict_types = 1);
 
-$number = mt_rand(max: 5);
+$number = mt_rand(0, 5);

In a partial function application, cover the parameter with a ? placeholder instead of leaving it to ...:

-$setter = $reflectionProperty->setValue(?, ...);
+$setter = $reflectionProperty->setValue(?, ?);

How to ignore this error #

You can use the identifier argument.unknownDefaultValue to ignore this error using a comment:

// @phpstan-ignore argument.unknownDefaultValue
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.unknownDefaultValue

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\FunctionCallableRule [1]
  • PHPStan\Rules\Functions\ParamAttributesRule [1]
  • PHPStan\Rules\Methods\CallMethodsRule [1]
  • PHPStan\Rules\Methods\CallStaticMethodsRule [1]
  • PHPStan\Rules\Methods\MethodAttributesRule [1]
  • PHPStan\Rules\Methods\MethodCallableRule [1]
  • PHPStan\Rules\Methods\StaticMethodCallableRule [1]
  • PHPStan\Rules\Properties\PropertyAttributesRule [1]
  • PHPStan\Rules\Properties\PropertyHookAttributesRule [1]
  • PHPStan\Rules\Traits\TraitAttributesRule [1]
Theme
© 2026 PHPStan s.r.o.