Menu

← Back to typeAlias.*

Error Identifier: typeAlias.invalidName

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

/**
 * @phpstan-type int \stdClass
 */
class Foo
{
}

Why is it reported? #

The name used for a PHPDoc type alias (@phpstan-type or @phpstan-import-type ... as) conflicts with a built-in PHP type name. Names like int, string, float, bool, array, null, void, never, mixed, object, callable, iterable, self, and parent cannot be used as type alias names because they already have special meaning in PHP’s type system.

Using such a name would make it ambiguous whether the type refers to the built-in type or the alias.

How to fix it #

Choose a different name for the type alias that does not conflict with built-in PHP types:

 <?php declare(strict_types = 1);
 
 /**
- * @phpstan-type int \stdClass
+ * @phpstan-type MyObject \stdClass
  */
 class Foo
 {
 }

For imported type aliases, change the alias name:

 <?php declare(strict_types = 1);
 
 /**
- * @phpstan-import-type ExportedAlias from OtherClass as int
+ * @phpstan-import-type ExportedAlias from OtherClass as MyAlias
  */
 class Foo
 {
 }

How to ignore this error #

You can use the identifier typeAlias.invalidName to ignore this error using a comment:

// @phpstan-ignore typeAlias.invalidName
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: typeAlias.invalidName

Rules that report this error #

  • PHPStan\Rules\Classes\LocalTypeAliasesRule [1] [2]
  • PHPStan\Rules\Classes\LocalTypeTraitAliasesRule [1] [2]
  • PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule [1] [2]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.