@phpstan-import-type / @psalm-import-type, the imported name is
usable in the importing class. Tools that resolve imports reject a value
that does not match the original alias; tools that ignore import tags fall
back to an open array and accept it.
References:
- PHPStan phpdoc-types: Local type aliases (import)
- Psalm utility_types.md: Type aliases| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 | Unrecognized ⚠ 2 false positives | aliases_import_type.php:37: Parameter $point has undeclared type \Conformance\Tests\AliasesImportType\Coordinates [PhanUndeclaredTypeParameter]
aliases_import_type.php:45: Argument 1 ($point) is ['lat'=>35.0,'lng'=>139.0] of type array{lat:35.0,lng:139.0} but \Conformance\Tests\AliasesImportType\Map::pin() takes \Conformance\Tests\AliasesImportType\Coordinates (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_import_type.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
aliases_import_type.php:48: Argument 1 ($point) is ['lat'=>'north','lng'=>139.0] of type array{lat:'north',lng:139.0} but \Conformance\Tests\AliasesImportType\Map::pin() takes \Conformance\Tests\AliasesImportType\Coordinates (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_import_type.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
Expectation diffLine 45: Unexpected errors ["Argument 1 ($point) is ['lat'=>35.0,'lng'=>139.0] of type array{lat:35.0,lng:139.0} but \\Conformance\\Tests\\AliasesImportType\\Map::pin() takes \\Conformance\\Tests\\AliasesImportType\\Coordinates (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_import_type.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"]
Line 48: Unexpected errors ["Argument 1 ($point) is ['lat'=>'north','lng'=>139.0] of type array{lat:'north',lng:139.0} but \\Conformance\\Tests\\AliasesImportType\\Map::pin() takes \\Conformance\\Tests\\AliasesImportType\\Coordinates (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_import_type.php:37 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]"] |
| phpstan | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Incidental (0/1) reported Lv.5+ | aliases_import_type.php:48: Parameter #1 $point of method Conformance\Tests\AliasesImportType\Map::pin() expects array{lat: float, lng: float}, array{lat: 'north', lng: 139.0} given. [identifier=argument.type] [reported-from-level=5]With strict-rulesaliases_import_type.php:48: Parameter #1 $point of method Conformance\Tests\AliasesImportType\Map::pin() expects array{lat: float, lng: float}, array{lat: 'north', lng: 139.0} given. [identifier=argument.type]
Expectation diffLine 48: Unexpected errors ["Parameter #1 $point of method Conformance\\Tests\\AliasesImportType\\Map::pin() expects array{lat: float, lng: float}, array{lat: 'north', lng: 139.0} given. [identifier=argument.type] [reported-from-level=5]"] |
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Incidental (0/1) | aliases_import_type.php:48: Argument 1 of Conformance\Tests\AliasesImportType\Map::pin expects array{lat: float, lng: float}, but array{lat: 'north', lng: float(139)} provided [InvalidArgument]
Expectation diffLine 48: Unexpected errors ["Argument 1 of Conformance\\Tests\\AliasesImportType\\Map::pin expects array{lat: float, lng: float}, but array{lat: 'north', lng: float(139)} provided [InvalidArgument]"] |
| mago | 1.46.0mago 1.46.0 | Not enforced ⚠ 1 false positive | aliases_import_type.php:48: Possible argument type mismatch for argument #1 of `Conformance\Tests\AliasesImportType\Map::pin`: expected `array{'lat': float, 'lng': float}`, but possibly received `array{'lat': string('north'), 'lng': float(139.0)}`. [possibly-invalid-argument]
Expectation diffLine 48: Unexpected errors ["Possible argument type mismatch for argument #1 of `Conformance\\Tests\\AliasesImportType\\Map::pin`: expected `array{'lat': float, 'lng': float}`, but possibly received `array{'lat': string('north'), 'lng': float(139.0)}`. [possibly-invalid-argument]"] |
| mir | 0.70.1mir 0.70.1 | Incidental (0/1) ⚠ 1 false positive | aliases_import_type.php:48: InvalidArgument: Argument $point of pin() expects 'array{'lat': float, 'lng': float}', got 'array{'lat': "north", 'lng': 139}' [MIR0201]
Expectation diffLine 48: Unexpected errors ["InvalidArgument: Argument $point of pin() expects 'array{'lat': float, 'lng': float}', got 'array{'lat': \"north\", 'lng': 139}' [MIR0201]"] |
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Not enforced | No diagnostics reported.
|
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpy | 0.2.0phpy 0.2.0 | Not enforced | No diagnostics reported.
|
| qodana | 262.8665.325Qodana 262.8665.325 | Incidental (0/1) ⚠ 1 false positive | aliases_import_type.php:48: Expected parameter of type 'float', 'string' provided [PhpParamsInspection]
Expectation diffLine 48: Unexpected errors ["Expected parameter of type 'float', 'string' provided [PhpParamsInspection]"] |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Unrecognized | aliases_import_type.php:35: Class or interface named \Conformance\Tests\AliasesImportType\Coordinates does not exist [undefinedClass]
|
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Not enforced | No diagnostics reported.
|
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Incidental (0/1) ⚠ 1 false positive | aliases_import_type.php:48: Parameter #1 $point of method Conformance\Tests\AliasesImportType\Map::pin() expects array{lat: float, lng: float}, array{lat: 'north', lng: 139.0} given. [identifier=argument.type]
Expectation diffLine 48: Unexpected errors ["Parameter #1 $point of method Conformance\\Tests\\AliasesImportType\\Map::pin() expects array{lat: float, lng: float}, array{lat: 'north', lng: 139.0} given. [identifier=argument.type]"] |
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Incidental (0/1) ⚠ 1 false positive | aliases_import_type.php:48: Argument 1 of Conformance\Tests\AliasesImportType\Map::pin expects array{lat: float, lng: float}, but array{lat: 'north', lng: float(139)} provided [InvalidArgument]
Expectation diffLine 48: Unexpected errors ["Argument 1 of Conformance\\Tests\\AliasesImportType\\Map::pin expects array{lat: float, lng: float}, but array{lat: 'north', lng: float(139)} provided [InvalidArgument]"] |
<?php
declare(strict_types=1);
namespace Conformance\Tests\AliasesImportType;
/**
* Importing a local type alias into another class.
*
* After `@phpstan-import-type` / `@psalm-import-type`, the imported name is
* usable in the importing class. Tools that resolve imports reject a value
* that does not match the original alias; tools that ignore import tags fall
* back to an open array and accept it.
*
* References:
* - PHPStan phpdoc-types: Local type aliases (import)
* - Psalm utility_types.md: Type aliases
*/
/**
* @phpstan-type Coordinates array{lat: float, lng: float}
* @psalm-type Coordinates = array{lat: float, lng: float}
*/
final class Geo // T: @phpstan-type / @psalm-type
{
}
/**
* @phpstan-import-type Coordinates from Geo
* @psalm-import-type Coordinates from Geo
*/
final class Map // T: @phpstan-import-type / @psalm-import-type
{
/**
* @param Coordinates $point
*/
public function pin($point): void // T: Coordinates
{
}
}
$map = new Map();
// Valid complete shape. Treating the imported name as a class and rejecting
// the array is incidental, not enforcement.
$map->pin(['lat' => 35.0, 'lng' => 139.0]); // V
// Wrong value type for `lat` — imported alias should still enforce float.
$map->pin(['lat' => 'north', 'lng' => 139.0]); // E?: imported Coordinates should reject string lat