Menu

← Back to property.*

Error Identifier: property.unusedType

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 Logger
{
	private string|int $level;

	public function __construct()
	{
		$this->level = 'info';
	}

	public function setLevel(string $level): void
	{
		$this->level = $level;
	}
}

Why is it reported? #

The property has a union type declaration, but one of the types in the union is never actually assigned to the property. PHPStan analyses all assignments to the property (including the default value) and determines that a part of the declared type is unused. In the example above, the property declares string|int, but only string values are ever assigned. The int part of the union type is unnecessary.

This helps catch overly broad type declarations that make the code harder to reason about and can hide type-related bugs.

How to fix it #

Remove the unused type from the property’s type declaration:

 <?php declare(strict_types = 1);
 
 class Logger
 {
-	private string|int $level;
+	private string $level;

 	public function __construct()
 	{
 		$this->level = 'info';
 	}

 	public function setLevel(string $level): void
 	{
 		$this->level = $level;
 	}
 }

If the broader type is intentional because future code will assign values of the additional type, add the missing assignment path to make the type accurate.

How to ignore this error #

You can use the identifier property.unusedType to ignore this error using a comment:

// @phpstan-ignore property.unusedType
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: property.unusedType

Rules that report this error #

  • PHPStan\Rules\TooWideTypehints\TooWideArrowFunctionReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideClosureReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideFunctionParameterOutTypeRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideFunctionReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideMethodParameterOutTypeRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideMethodReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWidePropertyTypeRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.