← All results

Generic iterable syntax in PHPDoc

Group: PHPDoc basics · Category: phpdoc · File: phpdoc_basics_iterable_generic_syntax.php

References: - PHPStan iterable types - Psalm iterable types

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 Enforced
phpdoc_basics_iterable_generic_syntax.php:32: Argument 1 ($values) is [1] of type array{0:1} but \Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesStringIterable() takes iterable<string> defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_basics_iterable_generic_syntax.php:18 [PhanTypeMismatchArgument]
phpdoc_basics_iterable_generic_syntax.php:33: Argument 1 ($values) is ['one'=>'one'] of type array{one:'one'} but \Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesIntegerStringIterable() takes iterable<int,string> defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_basics_iterable_generic_syntax.php:25 [PhanTypeMismatchArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpstan 2.2.11PHPStan - PHP Static Analysis Tool 2.2.11 Enforced reported Lv.5+
phpdoc_basics_iterable_generic_syntax.php:32: Parameter #1 $values of function Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesStringIterable expects iterable<string>, array<int, int> given. [reported-from-level=5]
phpdoc_basics_iterable_generic_syntax.php:33: Parameter #1 $values of function Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesIntegerStringIterable expects iterable<int, string>, array<string, string> given. [reported-from-level=5]
With strict-rules
phpdoc_basics_iterable_generic_syntax.php:32: Parameter #1 $values of function Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesStringIterable expects iterable<string>, array<int, int> given.
phpdoc_basics_iterable_generic_syntax.php:33: Parameter #1 $values of function Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesIntegerStringIterable expects iterable<int, string>, array<string, string> given.
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Enforced
phpdoc_basics_iterable_generic_syntax.php:32: Argument 1 of Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesStringIterable expects iterable<mixed, string>, but list{1} provided [InvalidArgument]
phpdoc_basics_iterable_generic_syntax.php:33: Argument 1 of Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesIntegerStringIterable expects iterable<int, string>, but array{one: 'one'} provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mago 1.47.4mago 1.47.4 Enforced
phpdoc_basics_iterable_generic_syntax.php:32: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesStringIterable`: expected `iterable<mixed, string>`, but possibly received `list{int(1)}`. [possibly-invalid-argument]
phpdoc_basics_iterable_generic_syntax.php:33: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesIntegerStringIterable`: expected `iterable<int, string>`, but possibly received `array{'one': string('one')}`. [possibly-invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mir 0.72.1mir 0.72.1 Partly enforced (1/2)
phpdoc_basics_iterable_generic_syntax.php:32: InvalidArgument: Argument $values of takesStringIterable() expects 'iterable<int|string, string>', got 'array{0: 1}' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
phpantom 0.10.0phpantom_lsp 0.10.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/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.07.22.0Phpactor 2026.07.22.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpy 0.2.0phpy 0.2.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
qodana 262.9437.196Qodana 262.9437.196 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_basics_iterable_generic_syntax.php:18: param $values miss matched with phpdoc type <<iterable<string>>> [funcParamTypeMissMatch]
phpdoc_basics_iterable_generic_syntax.php:25: param $values miss matched with phpdoc type <<iterable<int, string>>> [funcParamTypeMissMatch]
  • Recognition: spelling not resolved — reported on declaration line(s) 18, 25
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
steins 0.1.6steins 0.1.6 (2026-08-25 revision c13b4c7) Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpstan-strict 2.2.11PHPStan - PHP Static Analysis Tool 2.2.11 Enforced
phpdoc_basics_iterable_generic_syntax.php:32: Parameter #1 $values of function Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesStringIterable expects iterable<string>, array<int, int> given.
phpdoc_basics_iterable_generic_syntax.php:33: Parameter #1 $values of function Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesIntegerStringIterable expects iterable<int, string>, array<string, string> given.
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Enforced
phpdoc_basics_iterable_generic_syntax.php:32: Argument 1 of Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesStringIterable expects iterable<mixed, string>, but list{1} provided [InvalidArgument]
phpdoc_basics_iterable_generic_syntax.php:33: Argument 1 of Conformance\Tests\PhpdocBasicsIterableGenericSyntax\takesIntegerStringIterable expects iterable<int, string>, but array{one: 'one'} provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocBasicsIterableGenericSyntax;

/**
 * Generic iterable syntax in PHPDoc.
 *
 * References:
 * - PHPStan iterable types
 * - Psalm iterable types
 */

/**
 * @param iterable<string> $values
 */
function takesStringIterable(iterable $values): void // T: iterable<string>
{
}

/**
 * @param iterable<int, string> $values
 */
function takesIntegerStringIterable(iterable $values): void // T: iterable<int, string>
{
}

takesStringIterable(['one', 'two']); // V
takesIntegerStringIterable([1 => 'one', 2 => 'two']); // V

takesStringIterable([1]); // E?: an iterable of integers is not an iterable of strings
takesIntegerStringIterable(['one' => 'one']); // E?: the iterable key type is int