← All results

Basic instanceof-based narrowing checks

Group: Assertions and narrowing · Category: ecosystem · File: assertions_instanceof_narrowing.php

References: - common analyzer narrowing on instanceof branches

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.10Phan 6.0.10 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 Pass
assertions_instanceof_narrowing.php:46: Call to undeclared method \Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name [PhanUndeclaredMethod]
phpstan 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 Pass reported Lv.2+
assertions_instanceof_narrowing.php:46: Call to an undefined method Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name(). [reported-from-level=2]
With strict-rules
assertions_instanceof_narrowing.php:46: Call to an undefined method Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name().
psalm 6.20.0Psalm 6.20.0@804f03c0c183d149fcd4b8c7c0c9b3fbf836d34c
next: 7.0.0-rc2
Pass
assertions_instanceof_narrowing.php:46: Method Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name does not exist [UndefinedMethod]
mago 1.57.0mago 1.57.0 Pass
assertions_instanceof_narrowing.php:46: Method `name` does not exist on type `Conformance\Tests\AssertionsInstanceofNarrowing\Guest`. [non-existent-method]
mir 0.87.0mir 0.87.0 Pass
assertions_instanceof_narrowing.php:46: UndefinedMethod: Method Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name() does not exist [MIR0004]
phpantom 0.11.1phpantom_lsp 0.11.1 Pass
assertions_instanceof_narrowing.php:46: Method 'name' not found on class 'Conformance\Tests\AssertionsInstanceofNarrowing\Guest' [unknown_member]
intelephense 1.18.5intelephense 1.18.5 Pass
assertions_instanceof_narrowing.php:46: Undefined method 'name'. [P1013]
phpactor 2026.10.07.0Phpactor 2026.10.07.0 Pass
assertions_instanceof_narrowing.php:46: Method "name" does not exist on class "Conformance\Tests\AssertionsInstanceofNarrowing\Guest" [missing_member]
phpy 1.0.19409phpy 1.0.19409 Pass
assertions_instanceof_narrowing.php:46: Call to unknown method: Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name()
qodana 262.10968.76PhpStorm 262.10968.76 Fail
assertions_instanceof_narrowing.php:37: Argument type does not match the declared [PhpDocSignatureInspection]
Expectation diff
Line 46: Expected 1 error(s)
Line 37: Unexpected errors ["Argument type does not match the declared [PhpDocSignatureInspection]"]
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Fail
assertions_instanceof_narrowing.php:39: param $value miss matched with phpdoc type <<User|Guest>> [funcParamTypeMissMatch]
assertions_instanceof_narrowing.php:46: Call to undefined method {\Conformance\Tests\AssertionsInstanceofNarrowing\Guest|object}->name() [undefinedMethod]
Expectation diff
Line 39: Unexpected errors ["param $value miss matched with phpdoc type <<User|Guest>> [funcParamTypeMissMatch]"]
steins 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) Pass
assertions_instanceof_narrowing.php:46: call to undefined method Guest::name() — declared receiver $value narrowed to {Guest}, hierarchy and descendants fully enumerated, no __call, no @method/@property/@mixin [phpdoc.undefined-method]
phpstan-strict 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 Pass
assertions_instanceof_narrowing.php:46: Call to an undefined method Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name().
psalm-next 7.0.0-rc2Psalm 7.0.0-rc2@20339e3fe5b8d03bcd8061030eb2a83ad50e5783 Pass
assertions_instanceof_narrowing.php:46: Method Conformance\Tests\AssertionsInstanceofNarrowing\Guest::name does not exist [UndefinedMethod]

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\AssertionsInstanceofNarrowing;

/**
 * Basic instanceof-based narrowing checks.
 *
 * References:
 * - common analyzer narrowing on instanceof branches
 */

interface Named
{
    public function name(): string;
}

final class User implements Named
{
    #[\Override]
    public function name(): string
    {
        return 'user';
    }
}

final class Guest
{
    public function guestId(): int
    {
        return 1;
    }
}

/**
 * @param User|Guest $value
 */
function takesUserOrGuest(object $value): void
{
    if ($value instanceof User) {
        echo $value->name();
        return;
    }

    $value->name(); // E: Guest branch should not expose User methods
}