← All results

Alias spellings of post-call receiver updates

Group: Advanced PHPDoc types · Category: ecosystem · File: phpdoc_advanced_this_out_aliases.php

assertions_this_out_self_out measures the canonical pair @psalm-this-out / @phpstan-self-out. Psalm and PHPStan each document the swapped names as aliases (@psalm-self-out, @phpstan-this-out). References: - Psalm adding_assertions.md: @psalm-this-out aliases @psalm-self-out / @phpstan-self-out / @phpstan-this-out - PHPStan phpdocs-basics: @phpstan-self-out or @phpstan-this-out

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.11Phan 6.0.11 php-ast version 1.1.3 PHP version used to run Phan: 8.5.12 Partly enforced (1/2)
phpdoc_advanced_this_out_aliases.php:36: Template type U not used in return value of function/method replace() [PhanTemplateTypeNotUsedInFunctionReturn]
phpdoc_advanced_this_out_aliases.php:56: Argument 1 ($box) is $box of type \Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox|\Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<1> but \Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox() takes \Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> (real type \Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_this_out_aliases.php:47 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
phpdoc_advanced_this_out_aliases.php:62: Argument 1 ($box) is $box of type \Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox|\Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<1> but \Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox() takes \Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> (real type \Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_this_out_aliases.php:47 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
phpstan 2.3.7PHPStan - PHP Static Analysis Tool 2.3.7 Enforced reported Lv.5+
phpdoc_advanced_this_out_aliases.php:56: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int> given. [reported-from-level=5]
phpdoc_advanced_this_out_aliases.php:63: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesIntBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> given. [reported-from-level=5]
With strict-rules
phpdoc_advanced_this_out_aliases.php:56: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int> given.
phpdoc_advanced_this_out_aliases.php:63: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesIntBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> given.
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpstan-strict 2.3.7PHPStan - PHP Static Analysis Tool 2.3.7 Enforced
phpdoc_advanced_this_out_aliases.php:56: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int> given.
phpdoc_advanced_this_out_aliases.php:63: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesIntBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> given.
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm 6.21.4Psalm 6.21.4@72023213487628df0bc5b2e02d68cbac614b7ef5 Enforced
phpdoc_advanced_this_out_aliases.php:56: Type 1 should be a subtype of string [IncompatibleTypeParameters]
phpdoc_advanced_this_out_aliases.php:63: Argument 1 of Conformance\Tests\PhpdocAdvancedThisOutAliases\takesIntBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>, but Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm 7 7.21.0Psalm 7.21.0@1a665f0114bd40cf12ad57a1a82066549d92f1b6 Enforced
phpdoc_advanced_this_out_aliases.php:56: Type 1 should be a subtype of string [IncompatibleTypeParameters]
phpdoc_advanced_this_out_aliases.php:63: Argument 1 of Conformance\Tests\PhpdocAdvancedThisOutAliases\takesIntBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>, but Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mago 1.61.0mago 1.61.0 Incidental (1/2) ⚠ 1 false positive
phpdoc_advanced_this_out_aliases.php:57: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox`: expected `Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>`, but found `Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>`. [invalid-argument]
phpdoc_advanced_this_out_aliases.php:63: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox`: expected `Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>`, but found `Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>`. [invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 57
  • False positives: line(s) 57
Expectation diff
Line 57: Unexpected errors ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedThisOutAliases\\takesStringBox`: expected `Conformance\\Tests\\PhpdocAdvancedThisOutAliases\\MutableBox<string>`, but found `Conformance\\Tests\\PhpdocAdvancedThisOutAliases\\MutableBox<int>`. [invalid-argument]"]
mir 0.101.0mir 0.101.0 Enforced
phpdoc_advanced_this_out_aliases.php:56: InvalidArgument: Argument $box of takesStringBox() expects 'Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>', got 'Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>' [MIR0201]
phpdoc_advanced_this_out_aliases.php:63: InvalidArgument: Argument $box of takesIntBox() expects 'Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>', got 'Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpantom 1.1.0phpantom_lsp 1.1.0 Enforced
phpdoc_advanced_this_out_aliases.php:56: Argument 1 ($box) expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>, got Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int> [type_mismatch_argument]
phpdoc_advanced_this_out_aliases.php:63: Argument 1 ($box) expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>, got Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
pun 0.4.3pun 0.4.3 Enforced
phpdoc_advanced_this_out_aliases.php:56: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesStringBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int> given. [argument.type]
phpdoc_advanced_this_out_aliases.php:63: Parameter #1 $box of function Conformance\Tests\PhpdocAdvancedThisOutAliases\takesIntBox expects Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<int>, Conformance\Tests\PhpdocAdvancedThisOutAliases\MutableBox<string> given. [argument.type]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpactor 2026.11.22.0Phpactor 2026.11.22.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpy 1.0.19566phpy 1.0.19566 Enforced
phpdoc_advanced_this_out_aliases.php:56: Type 'MutableBox<int>' does not satisfy 'MutableBox<string>'
phpdoc_advanced_this_out_aliases.php:63: Type 'MutableBox<string>' does not satisfy 'MutableBox<int>'
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
qodana 263.7307.215PhpStorm 263.7307.215 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/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
phpdoc_advanced_this_out_aliases.php:26: param $value miss matched with phpdoc type <<T>> [funcParamTypeMissMatch]
phpdoc_advanced_this_out_aliases.php:32: Class or interface named \Conformance\Tests\PhpdocAdvancedThisOutAliases\U does not exist [undefinedClass]
phpdoc_advanced_this_out_aliases.php:36: param $value miss matched with phpdoc type <<U>> [funcParamTypeMissMatch]
phpdoc_advanced_this_out_aliases.php:42: param $box miss matched with phpdoc type <<MutableBox<int>>> [funcParamTypeMissMatch]
phpdoc_advanced_this_out_aliases.php:47: param $box miss matched with phpdoc type <<MutableBox<string>>> [funcParamTypeMissMatch]
  • Recognition: spelling not resolved — reported on declaration line(s) 32, 36
  • Enforcement: 5/7 of the expected violations reported — incidental, since the spelling was not resolved
steins 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) Partly enforced (1/2)
phpdoc_advanced_this_out_aliases.php:56: argument new MutableBox() to takesStringBox() violates declared @param MutableBox<string> $box — declared contract violation [phpdoc.param-mismatch]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedThisOutAliases;

/**
 * Alias spellings of post-call receiver updates.
 *
 * `assertions_this_out_self_out` measures the canonical pair
 * `@psalm-this-out` / `@phpstan-self-out`. Psalm and PHPStan each document
 * the swapped names as aliases (`@psalm-self-out`, `@phpstan-this-out`).
 *
 * References:
 * - Psalm adding_assertions.md: `@psalm-this-out` aliases `@psalm-self-out` / `@phpstan-self-out` / `@phpstan-this-out`
 * - PHPStan phpdocs-basics: `@phpstan-self-out` or `@phpstan-this-out`
 */

/**
 * @template T
 */
final class MutableBox
{
    /** @param T $value */
    public function __construct(
        public mixed $value, // E<noverify>: NoVerify does not reconcile the promoted property with the template-bound constructor param
    ) {
    }

    /**
     * @template U
     * @param U $value // E<noverify>: NoVerify does not understand method-level template parameters here
     * @psalm-self-out self<U>
     * @phpstan-this-out self<U>
     */
    public function replace(mixed $value): void // T: @psalm-self-out / @phpstan-this-out // E<noverify>: NoVerify treats the method template param as an unresolved class name
    {
    }
}

/** @param MutableBox<int> $box */
function takesIntBox(MutableBox $box): void // E<noverify>: NoVerify does not accept this generic parameter annotation on the function parameter
{
}

/** @param MutableBox<string> $box */
function takesStringBox(MutableBox $box): void // E<noverify>: NoVerify does not accept this generic parameter annotation on the function parameter
{
}

function inspectReplacement(string $next): void
{
    $box = new MutableBox(1);

    takesIntBox($box); // V
    takesStringBox($box); // E?: int box should not satisfy string box before replacement

    $box->replace($next);

    // Honouring either alias types the receiver as MutableBox<string>.
    // Tools that ignore both aliases still see MutableBox<int> here.
    takesStringBox($box); // E?[noise]
    takesIntBox($box); // E?: replacement should update MutableBox<int> to MutableBox<string>
}