associative-arrayassociative-array<K, V> as an array that is specifically not a
list, so a plain list argument is rejected. PHPStan and Psalm accept
associative-array only as a semantic alias of array, so they accept the
same list. This records that divergence in meaning.
References:
- Phan Type/AssociativeArrayType.php (array that is not a list)
- PHPStan/Psalm treat associative-array as an array alias| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 | Enforced | phpdoc_advanced_associative_array.php:32: Argument 1 ($map) is ['a','b','c'] of type array{0:'a',1:'b',2:'c'} but \Conformance\Tests\PhpdocAdvancedAssociativeArray\acceptsAssoc() takes associative-array<int,string> defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_associative_array.php:23 [PhanTypeMismatchArgument]
|
| phpstan | 2.2.11PHPStan - PHP Static Analysis Tool 2.2.11 | Widened to array | No diagnostics reported.
|
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Widened to array (pzoom≠) | pzoom (Psalm port)phpdoc_advanced_associative_array.php:23: Parameter $map has wrong type 'Conformance\Tests\PhpdocAdvancedAssociativeArray\associative-array<int, string>', should be 'array<array-key, mixed>' [MismatchingDocblockParamType]
phpdoc_advanced_associative_array.php:23: Docblock class Conformance\Tests\PhpdocAdvancedAssociativeArray\associative-array does not exist [UndefinedDocblockClass]
phpdoc_advanced_associative_array.php:28: Argument 1 of acceptsAssoc expects Conformance\Tests\PhpdocAdvancedAssociativeArray\associative-array<int, string>, but array{5: 'a', 9: 'b'} provided [InvalidArgument]
phpdoc_advanced_associative_array.php:32: Argument 1 of acceptsAssoc expects Conformance\Tests\PhpdocAdvancedAssociativeArray\associative-array<int, string>, but list{'a', 'b', 'c'} provided [InvalidArgument]
|
| mago | 1.47.4mago 1.47.4 | Widened to array | No diagnostics reported.
|
| mir | 0.72.1mir 0.72.1 | Unrecognized | phpdoc_advanced_associative_array.php:23: MismatchingDocblockParamType: Docblock type 'array<int, string>&array{}' for $map does not match inferred 'array' [MIR0210]
phpdoc_advanced_associative_array.php:32: InvalidArgument: Argument $map of acceptsAssoc() expects 'array<int, string>&array{}', got 'array{0: "a", 1: "b", 2: "c"}' [MIR0201]
|
| phpantom | 0.10.0phpantom_lsp 0.10.0 | Not enforced | No diagnostics reported.
|
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | phpdoc_advanced_associative_array.php:21: Documented type is not compatible with the declared type. [P1131]
|
| phpactor | 2026.07.22.0Phpactor 2026.07.22.0 | Not enforced | No diagnostics reported.
|
| phpy | 0.2.0phpy 0.2.0 | Unrecognized | phpdoc_advanced_associative_array.php:21: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedAssociativeArray\associative-array'
|
| qodana | 262.9437.196Qodana 262.9437.196 | Unrecognized | phpdoc_advanced_associative_array.php:21: Argument type does not match the declared [PhpDocSignatureInspection] phpdoc_advanced_associative_array.php:21: Undefined class 'associative-array' [PhpUndefinedClassInspection]
|
| 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_associative_array.php:23: param $map miss matched with phpdoc type <<associative-array<int, string>>> [funcParamTypeMissMatch]
|
| steins | 0.1.6steins 0.1.6 (2026-08-25 revision c13b4c7) | Enforced | phpdoc_advanced_associative_array.php:32: argument ['a', 'b', 'c'] to acceptsAssoc() violates declared @param associative-array<int, string> $map — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.11PHPStan - PHP Static Analysis Tool 2.2.11 | Widened to array | No diagnostics reported.
|
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Widened to array | No diagnostics reported.
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedAssociativeArray;
/**
* `associative-array`
*
* Phan treats `associative-array<K, V>` as an array that is specifically not a
* list, so a plain list argument is rejected. PHPStan and Psalm accept
* `associative-array` only as a semantic alias of `array`, so they accept the
* same list. This records that divergence in meaning.
*
* References:
* - Phan Type/AssociativeArrayType.php (array that is not a list)
* - PHPStan/Psalm treat `associative-array` as an `array` alias
*/
/**
* @param associative-array<int, string> $map
*/
function acceptsAssoc(array $map): void // T: associative-array<int, string>
{
}
// A non-sequential int-keyed array is associative everywhere.
acceptsAssoc([5 => 'a', 9 => 'b']); // V
// A plain list has the same int-key/string-value element types, so alias-only
// analyzers accept it; Phan rejects it because a list is not associative.
acceptsAssoc(['a', 'b', 'c']); // E?: a list is not an associative-array (enforced by Phan)