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);
class UserRepository
{
/** @var array */
private $users;
/** @return array */
public function getAll(): array
{
return $this->users;
}
}
Why is it reported? #
An iterable type such as array is used without specifying the types of its values (and optionally keys). Without a value type, PHPStan cannot track what the iterable contains, reducing the effectiveness of type checking for any code that consumes the iterable.
This rule applies to properties, function/method return types, and function/method parameters. It is reported for any iterable type – array, iterable, Generator, and other traversable types – when the value type is missing.
How to fix it #
Specify the value type for the iterable using PHPDoc:
<?php declare(strict_types = 1);
class UserRepository
{
- /** @var array */
+ /** @var array<User> */
private $users;
- /** @return array */
+ /** @return array<User> */
public function getAll(): array
{
return $this->users;
}
}
If both keys and values matter, specify both:
<?php declare(strict_types = 1);
class UserRepository
{
- /** @var array */
+ /** @var array<int, User> */
private $users;
}
For a more specific array shape, use array shape syntax:
<?php declare(strict_types = 1);
-/** @return array */
+/** @return array{name: string, age: int} */
function getConfig(): array
{
return ['name' => 'app', 'age' => 1];
}
With bleeding edge enabled, running PHPStan with --fix fixes this error for return types by writing the value type inferred from the function body into the @return PHPDoc tag. Properties and parameters still have to be fixed manually. Public and protected methods that can be overridden are fixed only when the projectType configuration parameter is set to closed, because only then PHPStan knows all the overriding methods. With the default open, they are reported without a fix.
In PHPStan 1.x this error was possible to ignore with configuration parameter checkMissingIterableValueType: false but in PHPStan 2.0 this parameter was removed in favor of ignoring by identifier. Learn more in the upgrading guide.
🔧 This error is auto-fixable. PHPStan can fix it for you. Run the analysis with the --fix option to rewrite the affected code:
vendor/bin/phpstan analyse --fix
To also fix the errors you have ignored, use --fix-ignored. Learn more about --fix »
How to ignore this error #
You can use the identifier missingType.iterableValue to ignore this error using a comment:
// @phpstan-ignore missingType.iterableValue
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: missingType.iterableValue
Rules that report this error #
- PHPStan\Rules\Classes\FunctionTypeAliasesRule [1]
- PHPStan\Rules\Classes\LocalTypeAliasesRule [1]
- PHPStan\Rules\Classes\LocalTypeTraitAliasesRule [1]
- PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule [1]
- PHPStan\Rules\Classes\MethodTagRule [1]
- PHPStan\Rules\Classes\MethodTagTraitRule [1]
- PHPStan\Rules\Classes\MethodTagTraitUseRule [1]
- PHPStan\Rules\Classes\MixinRule [1]
- PHPStan\Rules\Classes\MixinTraitRule [1]
- PHPStan\Rules\Classes\MixinTraitUseRule [1]
- PHPStan\Rules\Classes\PropertyTagRule [1]
- PHPStan\Rules\Classes\PropertyTagTraitRule [1]
- PHPStan\Rules\Classes\PropertyTagTraitUseRule [1]
- PHPStan\Rules\Constants\MissingClassConstantTypehintRule [1]
- PHPStan\Rules\Functions\MissingFunctionParameterTypehintRule [1]
- PHPStan\Rules\Functions\MissingFunctionReturnTypehintRule [1]
- PHPStan\Rules\Methods\MissingImplementedMethodReturnTypehintRule [1]
- PHPStan\Rules\Methods\MissingMethodParameterTypehintRule [1]
- PHPStan\Rules\Methods\MissingMethodReturnTypehintRule [1]
- PHPStan\Rules\Methods\MissingMethodSelfOutTypeRule [1]
- PHPStan\Rules\MissingReturnTypeFixRule [1]
- PHPStan\Rules\PhpDoc\FunctionAssertRule [1]
- PHPStan\Rules\PhpDoc\InvalidPhpDocVarTagTypeRule [1]
- PHPStan\Rules\PhpDoc\MethodAssertRule [1]
- PHPStan\Rules\PhpDoc\PropertyAssertRule [1]
- PHPStan\Rules\PhpDoc\PropertyHookAssertRule [1]
- PHPStan\Rules\Properties\MissingPropertyTypehintRule [1]
- PHPStan\Rules\Properties\SetPropertyHookParameterRule [1]