← All results

non-empty-associative-array is a Phan-only array refinement

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

It combines two Phan refinements: the array must be non-empty and must not be a list. Phan models both; other analyzers do not recognize the keyword and fall back to plain array, accepting an empty array or a list. References: - Phan Type/NonEmptyAssociativeArrayType.php

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 Partly enforced (1/2)
phpdoc_advanced_phan_non_empty_associative_array.php:32: Argument 1 ($map) is [1,2,3] of type array{0:1,1:2,2:3} but \Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc() takes array<string,int> defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_phan_non_empty_associative_array.php:21 [PhanTypeMismatchArgument]
  • Recognition: spelling resolved
  • Enforcement: 1/2 of the expected violations reported
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Unrecognized
phpdoc_advanced_phan_non_empty_associative_array.php:21: Function Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc() has parameter $map with no value type specified in iterable type array. [identifier=missingType.iterableValue] [reported-from-level=6]
phpdoc_advanced_phan_non_empty_associative_array.php:21: PHPDoc tag @param for parameter $map contains unresolvable type. [identifier=parameter.unresolvableType] [reported-from-level=2]
With strict-rules
phpdoc_advanced_phan_non_empty_associative_array.php:21: Function Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc() has parameter $map with no value type specified in iterable type array. [identifier=missingType.iterableValue]
phpdoc_advanced_phan_non_empty_associative_array.php:21: PHPDoc tag @param for parameter $map contains unresolvable type. [identifier=parameter.unresolvableType]
  • Recognition: spelling not resolved — reported on declaration line(s) 21
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Unrecognized (pzoom≠)
phpdoc_advanced_phan_non_empty_associative_array.php:19: Docblock-defined class, interface or enum named Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array does not exist [UndefinedDocblockClass]
phpdoc_advanced_phan_non_empty_associative_array.php:19: Parameter $map has wrong type 'Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>', should be 'array<array-key, mixed>' [MismatchingDocblockParamType]
phpdoc_advanced_phan_non_empty_associative_array.php:26: Argument 1 of Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc expects Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>, but array{a: 1} provided [InvalidArgument]
phpdoc_advanced_phan_non_empty_associative_array.php:29: Argument 1 of Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc expects Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>, but array<never, never> provided [InvalidArgument]
phpdoc_advanced_phan_non_empty_associative_array.php:32: Argument 1 of Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc expects Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>, but list{1, 2, 3} provided [InvalidArgument]
pzoom (Psalm port)
phpdoc_advanced_phan_non_empty_associative_array.php:21: Invalid docblock type [InvalidDocblock]
  • Recognition: spelling not resolved — reported on declaration line(s) 19
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 26: Expected valid value to be accepted, got ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedPhanNonEmptyAssociativeArray\\acceptsNonEmptyAssoc expects Conformance\\Tests\\PhpdocAdvancedPhanNonEmptyAssociativeArray\\non-empty-associative-array<string, int>, but array{a: 1} provided [InvalidArgument]"]
mago 1.46.0mago 1.46.0 Unrecognized
phpdoc_advanced_phan_non_empty_associative_array.php:19: Cannot find class, interface, enum, or type alias `Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array`. [non-existent-class-like]
phpdoc_advanced_phan_non_empty_associative_array.php:21: Docblock type `unknown-ref(Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array)` for parameter `$map` is incompatible with native type `array<array-key, mixed>`. [docblock-type-mismatch]
phpdoc_advanced_phan_non_empty_associative_array.php:26: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array)`, but found `array{'a': int(1)}`. [invalid-argument]
phpdoc_advanced_phan_non_empty_associative_array.php:29: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array)`, but found `array{}`. [invalid-argument]
phpdoc_advanced_phan_non_empty_associative_array.php:32: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array)`, but found `list{int(1), int(2), int(3)}`. [invalid-argument]
  • Recognition: spelling not resolved — reported on declaration line(s) 19, 21
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 26: Expected valid value to be accepted, got ["Invalid argument type for argument #1 of `Conformance\\Tests\\PhpdocAdvancedPhanNonEmptyAssociativeArray\\acceptsNonEmptyAssoc`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedPhanNonEmptyAssociativeArray\\non-empty-associative-array)`, but found `array{'a': int(1)}`. [invalid-argument]"]
mir 0.70.1mir 0.70.1 Incidental (2/2)
phpdoc_advanced_phan_non_empty_associative_array.php:26: InvalidArgument: Argument $map of acceptsNonEmptyAssoc() expects 'Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>', got 'array{'a': 1}' [MIR0201]
phpdoc_advanced_phan_non_empty_associative_array.php:29: InvalidArgument: Argument $map of acceptsNonEmptyAssoc() expects 'Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>', got 'array{}' [MIR0201]
phpdoc_advanced_phan_non_empty_associative_array.php:32: InvalidArgument: Argument $map of acceptsNonEmptyAssoc() expects 'Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>', got 'array{0: 1, 1: 2, 2: 3}' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 26
Expectation diff
Line 26: Expected valid value to be accepted, got ["InvalidArgument: Argument $map of acceptsNonEmptyAssoc() expects 'Conformance\\Tests\\PhpdocAdvancedPhanNonEmptyAssociativeArray\\non-empty-associative-array<string, int>', got 'array{'a': 1}' [MIR0201]"]
phpantom 0.9.0phpantom_lsp 0.9.0 Unrecognized
phpdoc_advanced_phan_non_empty_associative_array.php:19: Class 'Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>' not found [unknown_class]
  • Recognition: spelling not resolved — reported on declaration line(s) 19
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
intelephense 1.18.5intelephense 1.18.5 Not enforced
phpdoc_advanced_phan_non_empty_associative_array.php:19: Documented type is not compatible with the declared type. [P1131]
  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpy 0.2.0phpy 0.2.0 Unrecognized
phpdoc_advanced_phan_non_empty_associative_array.php:19: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array'
  • Recognition: spelling not resolved — reported on declaration line(s) 19
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
qodana 262.8665.325Qodana 262.8665.325 Unrecognized
phpdoc_advanced_phan_non_empty_associative_array.php:19: Argument type does not match the declared [PhpDocSignatureInspection]
phpdoc_advanced_phan_non_empty_associative_array.php:19: Undefined class 'non-empty-associative-array' [PhpUndefinedClassInspection]
  • Recognition: spelling not resolved — reported on declaration line(s) 19
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
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_phan_non_empty_associative_array.php:21: param $map miss matched with phpdoc type <<non-empty-associative-array<string, int>>> [funcParamTypeMissMatch]
  • Recognition: spelling not resolved — reported on declaration line(s) 21
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Enforced
phpdoc_advanced_phan_non_empty_associative_array.php:29: argument [] to acceptsNonEmptyAssoc() violates declared @param non-empty-associative-array<string, int> $map — declared contract violation [phpdoc.param-mismatch]
phpdoc_advanced_phan_non_empty_associative_array.php:32: argument [1, 2, 3] to acceptsNonEmptyAssoc() violates declared @param non-empty-associative-array<string, int> $map — declared contract violation [phpdoc.param-mismatch]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Unrecognized
phpdoc_advanced_phan_non_empty_associative_array.php:21: Function Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc() has parameter $map with no value type specified in iterable type array. [identifier=missingType.iterableValue]
phpdoc_advanced_phan_non_empty_associative_array.php:21: PHPDoc tag @param for parameter $map contains unresolvable type. [identifier=parameter.unresolvableType]
  • Recognition: spelling not resolved — reported on declaration line(s) 21
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Unrecognized
phpdoc_advanced_phan_non_empty_associative_array.php:19: Docblock-defined class, interface or enum named Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array does not exist [UndefinedDocblockClass]
phpdoc_advanced_phan_non_empty_associative_array.php:19: Parameter $map has wrong type 'Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>', should be 'array<array-key, mixed>' [MismatchingDocblockParamType]
phpdoc_advanced_phan_non_empty_associative_array.php:26: Argument 1 of Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc expects Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>, but array{a: 1} provided [InvalidArgument]
phpdoc_advanced_phan_non_empty_associative_array.php:29: Argument 1 of Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc expects Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>, but array<never, never> provided [InvalidArgument]
phpdoc_advanced_phan_non_empty_associative_array.php:32: Argument 1 of Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\acceptsNonEmptyAssoc expects Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray\non-empty-associative-array<string, int>, but list{1, 2, 3} provided [InvalidArgument]
  • Recognition: spelling not resolved — reported on declaration line(s) 19
  • Enforcement: 2/2 of the expected violations reported — incidental, since the spelling was not resolved
Expectation diff
Line 26: Expected valid value to be accepted, got ["Argument 1 of Conformance\\Tests\\PhpdocAdvancedPhanNonEmptyAssociativeArray\\acceptsNonEmptyAssoc expects Conformance\\Tests\\PhpdocAdvancedPhanNonEmptyAssociativeArray\\non-empty-associative-array<string, int>, but array{a: 1} provided [InvalidArgument]"]

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedPhanNonEmptyAssociativeArray;

/**
 * `non-empty-associative-array` is a Phan-only array refinement.
 *
 * It combines two Phan refinements: the array must be non-empty and must not be
 * a list. Phan models both; other analyzers do not recognize the keyword and
 * fall back to plain `array`, accepting an empty array or a list.
 *
 * References:
 * - Phan Type/NonEmptyAssociativeArrayType.php
 */

/**
 * @param non-empty-associative-array<string, int> $map
 */
function acceptsNonEmptyAssoc(array $map): void // T: non-empty-associative-array<string, int>
{
}

// A non-empty string-keyed array satisfies the parameter.
acceptsNonEmptyAssoc(['a' => 1]); // V

// An empty array violates the non-empty part.
acceptsNonEmptyAssoc([]); // E?: an empty array is not a non-empty-associative-array

// A list violates the associative part.
acceptsNonEmptyAssoc([1, 2, 3]); // E?: a list is not an associative array