Menu

Error Identifier: parameter.defaultValue

← Back to parameter.*

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

function greet(int $count = "hello"): void
{
	echo $count;
}

Why is it reported? #

The default value of a parameter is incompatible with the parameter’s declared type. In the example above, the parameter $count is declared as int, but its default value is "hello", which is a string.

How to fix it #

Change the default value to match the declared type:

-function greet(int $count = "hello"): void
+function greet(int $count = 0): void
 {
 	echo $count;
 }

Or change the parameter type to match the default value:

-function greet(int $count = "hello"): void
+function greet(string $count = "hello"): void
 {
 	echo $count;
 }

How to ignore this error #

You can use the identifier parameter.defaultValue to ignore this error using a comment:

// @phpstan-ignore parameter.defaultValue
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: parameter.defaultValue

Rules that report this error #

  • PHPStan\Rules\Functions\IncompatibleArrowFunctionDefaultParameterTypeRule [1]
  • PHPStan\Rules\Functions\IncompatibleClosureDefaultParameterTypeRule [1]
  • PHPStan\Rules\Functions\IncompatibleDefaultParameterTypeRule [1]
  • PHPStan\Rules\Methods\IncompatibleDefaultParameterTypeRule [1]
Theme
A
© 2026 PHPStan s.r.o.