← All results

Parenthesized union types in @method parameters

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

@method void takeUnion((int|string) $x) should accept int and string and reject bool. A tool that cannot parse the parentheses drops the magic method or reads the parameter as mixed. Source: vimeo/psalm#12057 (6.19.2). References: - psalm#12057 - phpdoc_advanced_member_tag_undefined_type for @method with a missing class

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
phpdoc_advanced_method_parenthesized_union.php:22: Saw unextractable annotation for comment '* @method void takeUnion((int|string) $x)' [PhanUnextractableAnnotation]
phpdoc_advanced_method_parenthesized_union.php:41: Argument 1 ($x) is 'x' of type string but \Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeInt() takes int (no real type) defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_method_parenthesized_union.php:23 (the inferred real argument type has nothing in common with the parameter's phpdoc type) [PhanTypeMismatchArgumentProbablyReal]
  • Recognition: spelling not resolved — reported on declaration line(s) 22
  • Enforcement: 1/2 of the expected violations reported — incidental, since the spelling was not resolved
phpstan 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 Enforced reported Lv.5+
phpdoc_advanced_method_parenthesized_union.php:39: Parameter #1 $x of method Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeUnion() expects int|string, true given. [reported-from-level=5]
phpdoc_advanced_method_parenthesized_union.php:41: Parameter #1 $x of method Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeInt() expects int, string given. [reported-from-level=5]
With strict-rules
phpdoc_advanced_method_parenthesized_union.php:39: Parameter #1 $x of method Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeUnion() expects int|string, true given.
phpdoc_advanced_method_parenthesized_union.php:41: Parameter #1 $x of method Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeInt() 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
phpdoc_advanced_method_parenthesized_union.php:39: Argument 1 of takeUnion expects int|string, but true provided [InvalidArgument]
phpdoc_advanced_method_parenthesized_union.php:41: Argument 1 of takeInt expects int, but 'x' provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mago 1.59.0mago 1.59.0 Enforced
phpdoc_advanced_method_parenthesized_union.php:39: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeUnion`: expected `int|string`, but found `true`. [invalid-argument]
phpdoc_advanced_method_parenthesized_union.php:41: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeInt`: expected `int`, but found `string('x')`. [invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mir 0.91.0mir 0.91.0 Enforced
phpdoc_advanced_method_parenthesized_union.php:39: InvalidArgument: Argument $x of takeUnion() expects 'int|string', got 'true' [MIR0201]
phpdoc_advanced_method_parenthesized_union.php:41: InvalidArgument: Argument $x of takeInt() expects 'int', got '"x"' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpantom 0.11.1phpantom_lsp 0.11.1 Enforced
phpdoc_advanced_method_parenthesized_union.php:39: Argument 1 ($x) expects int|string, got true [type_mismatch_argument]
phpdoc_advanced_method_parenthesized_union.php:41: Argument 1 ($x) expects int, got 'x' [type_mismatch_argument]
  • 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
Expectation diff
Line 41: Expected 1 error(s)
phpactor 2026.10.07.0Phpactor 2026.10.07.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
Expectation diff
Line 41: Expected 1 error(s)
phpy 1.0.19490phpy 1.0.19490 Enforced
phpdoc_advanced_method_parenthesized_union.php:39: Argument '1' passed to takeUnion() is expected to be of type int|string, bool given
phpdoc_advanced_method_parenthesized_union.php:41: Argument '1' passed to takeInt() 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 Partly enforced (1/2)
phpdoc_advanced_method_parenthesized_union.php:41: Parameter ''x'' type is not compatible with declaration when using strict type matching [PhpParamsInspection]
phpdoc_advanced_method_parenthesized_union.php:41: Parameter ''x'' type is not compatible with declaration [PhpStrictTypeCheckingInspection]
  • Recognition: spelling resolved
  • Enforcement: 1/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 Not enforced
phpdoc_advanced_method_parenthesized_union.php:30: param $arguments miss matched with phpdoc type <<list<mixed>>> [funcParamTypeMissMatch]
  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
Expectation diff
Line 41: Expected 1 error(s)
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
Expectation diff
Line 41: Expected 1 error(s)
phpstan-strict 2.3.5PHPStan - PHP Static Analysis Tool 2.3.5 Enforced
phpdoc_advanced_method_parenthesized_union.php:39: Parameter #1 $x of method Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeUnion() expects int|string, true given.
phpdoc_advanced_method_parenthesized_union.php:41: Parameter #1 $x of method Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion\Magic::takeInt() 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
phpdoc_advanced_method_parenthesized_union.php:39: Argument 1 of takeUnion expects int|string, but true provided [InvalidArgument]
phpdoc_advanced_method_parenthesized_union.php:41: Argument 1 of takeInt expects int, but 'x' provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedMethodParenthesizedUnion;

/**
 * Parenthesized union types in `@method` parameters.
 *
 * `@method void takeUnion((int|string) $x)` should accept `int` and `string`
 * and reject `bool`. A tool that cannot parse the parentheses drops the
 * magic method or reads the parameter as `mixed`.
 *
 * Source: vimeo/psalm#12057 (6.19.2).
 *
 * References:
 * - https://github.com/vimeo/psalm/pull/12057
 * - phpdoc_advanced_member_tag_undefined_type for `@method` with a missing class
 */

/**
 * @method void takeUnion((int|string) $x)
 * @method void takeInt(int $x)
 */
final class Magic // T: @method
{
    /**
     * @param list<mixed> $arguments
     */
    public function __call(string $name, array $arguments): mixed // E?[noise]: some tools flag the docblock/native array mismatch
    {
        return null;
    }
}

$magic = new Magic();
$magic->takeUnion(1); // V
$magic->takeUnion('x'); // V
$magic->takeUnion(true); // E?: bool is not int|string
$magic->takeInt(1); // V
$magic->takeInt('x'); // E: takeInt wants int