← All results

Local type aliases on static properties

Group: Type aliases · Category: ecosystem · File: aliases_static_members.php

aliases_local_type uses an alias as a @param. This file asks whether the same expansion applies to a static property @var and a static method @return — native types are omitted so the alias is the only source of the int/string distinction. Source: vimeo/psalm#10362 (6.0.0). References: - psalm#10362

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 Unrecognized
aliases_static_members.php:32: Default value for \Conformance\Tests\AliasesStaticMembers\UserId $nextId can't be 1 of type int based on phpdoc types [PhanTypeMismatchPropertyDefault]
aliases_static_members.php:32: Property \Conformance\Tests\AliasesStaticMembers\User::$nextId has undeclared type \Conformance\Tests\AliasesStaticMembers\UserId (Did you mean class \Conformance\Tests\AliasesStaticMembers\User) [PhanUndeclaredTypeProperty]
aliases_static_members.php:37: Default value for \Conformance\Tests\AliasesStaticMembers\UserName $defaultName can't be 'guest' of type string based on phpdoc types [PhanTypeMismatchPropertyDefault]
aliases_static_members.php:37: Property \Conformance\Tests\AliasesStaticMembers\User::$defaultName has undeclared type \Conformance\Tests\AliasesStaticMembers\UserName [PhanUndeclaredTypeProperty]
aliases_static_members.php:42: Return type of getNextId() is undeclared type \Conformance\Tests\AliasesStaticMembers\UserId (Did you mean class \Conformance\Tests\AliasesStaticMembers\User) [PhanUndeclaredTypeReturnType]
aliases_static_members.php:50: Return type of getDefaultName() is undeclared type \Conformance\Tests\AliasesStaticMembers\UserName [PhanUndeclaredTypeReturnType]
aliases_static_members.php:64: Argument 1 ($value) is User::getNextId() of type \Conformance\Tests\AliasesStaticMembers\UserId but \Conformance\Tests\AliasesStaticMembers\takesInt() takes int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_static_members.php:56 [PhanTypeMismatchArgument]
aliases_static_members.php:65: Argument 1 ($value) is User::getNextId() of type \Conformance\Tests\AliasesStaticMembers\UserId but \Conformance\Tests\AliasesStaticMembers\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_static_members.php:60 [PhanTypeMismatchArgument]
aliases_static_members.php:66: Argument 1 ($value) is User::getDefaultName() of type \Conformance\Tests\AliasesStaticMembers\UserName but \Conformance\Tests\AliasesStaticMembers\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_static_members.php:60 [PhanTypeMismatchArgument]
aliases_static_members.php:67: Argument 1 ($value) is User::getDefaultName() of type \Conformance\Tests\AliasesStaticMembers\UserName but \Conformance\Tests\AliasesStaticMembers\takesInt() takes int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_static_members.php:56 [PhanTypeMismatchArgument]
  • Recognition: spelling not resolved — reported on declaration line(s) 32, 37, 42, 50
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 64: Expected valid value to be accepted, got ["Argument 1 ($value) is User::getNextId() of type \\Conformance\\Tests\\AliasesStaticMembers\\UserId but \\Conformance\\Tests\\AliasesStaticMembers\\takesInt() takes int defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_static_members.php:56 [PhanTypeMismatchArgument]"]
Line 66: Expected valid value to be accepted, got ["Argument 1 ($value) is User::getDefaultName() of type \\Conformance\\Tests\\AliasesStaticMembers\\UserName but \\Conformance\\Tests\\AliasesStaticMembers\\takesString() takes string defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/aliases_static_members.php:60 [PhanTypeMismatchArgument]"]
phpstan 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 Enforced reported Lv.5+
aliases_static_members.php:65: Parameter #1 $value of function Conformance\Tests\AliasesStaticMembers\takesString expects string, int given. [reported-from-level=5]
aliases_static_members.php:67: Parameter #1 $value of function Conformance\Tests\AliasesStaticMembers\takesInt expects int, string given. [reported-from-level=5]
With strict-rules
aliases_static_members.php:65: Parameter #1 $value of function Conformance\Tests\AliasesStaticMembers\takesString expects string, int given.
aliases_static_members.php:67: Parameter #1 $value of function Conformance\Tests\AliasesStaticMembers\takesInt expects int, string given.
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm 6.20.9Psalm 6.20.9@f67170ac3c3b931f5088681e21d6c8babc601c08
next: 7.0.4
Enforced
aliases_static_members.php:65: Argument 1 of Conformance\Tests\AliasesStaticMembers\takesString expects string, but int provided [InvalidScalarArgument]
aliases_static_members.php:67: Argument 1 of Conformance\Tests\AliasesStaticMembers\takesInt expects int, but string provided [InvalidScalarArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mago 1.59.0mago 1.59.0 Enforced
aliases_static_members.php:65: Invalid argument type for argument #1 of `Conformance\Tests\AliasesStaticMembers\takesString`: expected `string`, but found `int`. [invalid-argument]
aliases_static_members.php:67: Invalid argument type for argument #1 of `Conformance\Tests\AliasesStaticMembers\takesInt`: expected `int`, but found `string`. [invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mir 0.91.0mir 0.91.0 Enforced
aliases_static_members.php:65: InvalidArgument: Argument $value of takesString() expects 'string', got 'int' [MIR0201]
aliases_static_members.php:67: InvalidArgument: Argument $value of takesInt() expects 'int', got 'string' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpantom 0.11.1phpantom_lsp 0.11.1 Enforced
aliases_static_members.php:65: Argument 1 ($value) expects string, got int [type_mismatch_argument]
aliases_static_members.php:67: Argument 1 ($value) expects int, got string [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Enforced
aliases_static_members.php:65: Expected type 'string'. Found 'int'. [P1006]
aliases_static_members.php:67: Expected type 'int'. Found 'string'. [P1006]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpactor 2026.10.07.0Phpactor 2026.10.07.0 Unrecognized
aliases_static_members.php:42: Method "getNextId" is missing return type and the type could not be determined [missing_return_type]
aliases_static_members.php:50: Method "getDefaultName" is missing return type and the type could not be determined [missing_return_type]
  • Recognition: spelling not resolved — reported on declaration line(s) 42, 50
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
phpy 1.0.19490phpy 1.0.19490 Enforced
aliases_static_members.php:65: Argument '1' passed to Conformance\Tests\AliasesStaticMembers\takesString() is expected to be of type string, int given
aliases_static_members.php:67: Argument '1' passed to Conformance\Tests\AliasesStaticMembers\takesInt() is expected to be of type int, string given
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
qodana 262.11879.104PhpStorm 262.11879.104 Enforced
aliases_static_members.php:65: Parameter 'User::getNextId()' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
aliases_static_members.php:67: Parameter 'User::getDefaultName()' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Unrecognized
aliases_static_members.php:30: Class or interface named \Conformance\Tests\AliasesStaticMembers\UserId does not exist [undefinedClass]
aliases_static_members.php:35: Class or interface named \Conformance\Tests\AliasesStaticMembers\UserName does not exist [undefinedClass]
aliases_static_members.php:40: Class or interface named \Conformance\Tests\AliasesStaticMembers\UserId does not exist [undefinedClass]
aliases_static_members.php:48: Class or interface named \Conformance\Tests\AliasesStaticMembers\UserName does not exist [undefinedClass]
  • Recognition: spelling not resolved — reported on declaration line(s) 30, 35, 40, 48
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
steins 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpstan-strict 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 Enforced
aliases_static_members.php:65: Parameter #1 $value of function Conformance\Tests\AliasesStaticMembers\takesString expects string, int given.
aliases_static_members.php:67: Parameter #1 $value of function Conformance\Tests\AliasesStaticMembers\takesInt expects int, string given.
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm-next 7.0.4Psalm 7.0.4@fa5b1f6e665cb743838ffd865b8fc96207f9409f Enforced
aliases_static_members.php:65: Argument 1 of Conformance\Tests\AliasesStaticMembers\takesString expects string, but int provided [InvalidScalarArgument]
aliases_static_members.php:67: Argument 1 of Conformance\Tests\AliasesStaticMembers\takesInt expects int, but string provided [InvalidScalarArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\AliasesStaticMembers;

/**
 * Local type aliases on static properties.
 *
 * `aliases_local_type` uses an alias as a `@param`. This file asks whether
 * the same expansion applies to a static property `@var` and a static
 * method `@return` — native types are omitted so the alias is the only
 * source of the int/string distinction.
 *
 * Source: vimeo/psalm#10362 (6.0.0).
 *
 * References:
 * - https://github.com/vimeo/psalm/pull/10362
 */

/**
 * @phpstan-type UserId int
 * @phpstan-type UserName string
 * @psalm-type UserId = int
 * @psalm-type UserName = string
 */
final class User // T: @phpstan-type / @psalm-type
{
    /**
     * @var UserId
     */
    private static $nextId = 1; // T: UserId

    /**
     * @var UserName
     */
    private static $defaultName = 'guest'; // T: UserName

    /**
     * @return UserId
     */
    public static function getNextId() // T: UserId
    {
        return self::$nextId;
    }

    /**
     * @return UserName
     */
    public static function getDefaultName() // T: UserName
    {
        return self::$defaultName;
    }
}

function takesInt(int $value): void
{
}

function takesString(string $value): void
{
}

takesInt(User::getNextId()); // V
takesString(User::getNextId()); // E?: UserId is int
takesString(User::getDefaultName()); // V
takesInt(User::getDefaultName()); // E?: UserName is string