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.8PHPStan - PHP Static Analysis Tool 2.2.8 | 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.46.0mago 1.46.0 | Widened to array | No diagnostics reported.
|
| mir | 0.70.1mir 0.70.1 | Incidental (1/1) | phpdoc_advanced_associative_array.php:28: InvalidArgument: Argument $map of acceptsAssoc() expects 'Conformance\Tests\PhpdocAdvancedAssociativeArray\associative-array<int, string>', got 'array{5: "a", 9: "b"}' [MIR0201]
phpdoc_advanced_associative_array.php:32: InvalidArgument: Argument $map of acceptsAssoc() expects 'Conformance\Tests\PhpdocAdvancedAssociativeArray\associative-array<int, string>', got 'array{0: "a", 1: "b", 2: "c"}' [MIR0201]
Expectation diffLine 28: Expected valid value to be accepted, got ["InvalidArgument: Argument $map of acceptsAssoc() expects 'Conformance\\Tests\\PhpdocAdvancedAssociativeArray\\associative-array<int, string>', got 'array{5: \"a\", 9: \"b\"}' [MIR0201]"] |
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Incidental (1/1) | phpdoc_advanced_associative_array.php:28: Argument 1 ($map) expects associative-array<int, string>, got array{5: string, 9: string} [type_mismatch_argument]
phpdoc_advanced_associative_array.php:32: Argument 1 ($map) expects associative-array<int, string>, got list<string> [type_mismatch_argument]
Expectation diffLine 28: Expected valid value to be accepted, got ["Argument 1 ($map) expects associative-array<int, string>, got array{5: string, 9: string} [type_mismatch_argument]"] |
| 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]
|
| 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.8665.325Qodana 262.8665.325 | 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.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | 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.8PHPStan - PHP Static Analysis Tool 2.2.8 | 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)