non-empty-arraynon-empty-string, and the only member of this group whose base type can be
written natively, so the parameter can carry array in the signature and the
refinement in the docblock at once.
References:
- PHPStan TypeNodeResolver non-empty-array resolves to array&NonEmptyArrayType| 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_fallback_non_empty_array.php:49: Argument 1 ($value) is [] of type array{} but \Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray() takes non-empty-array<mixed,mixed> defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_fallback_non_empty_array.php:37 [PhanTypeMismatchArgument]
|
| phpstan | 2.2.15PHPStan - PHP Static Analysis Tool 2.2.15 | Enforced reported Lv.5+ | phpdoc_advanced_fallback_non_empty_array.php:49: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray expects non-empty-array<mixed>, array{} given. [reported-from-level=5]With strict-rulesphpdoc_advanced_fallback_non_empty_array.php:49: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray expects non-empty-array<mixed>, array{} given.
|
| psalm | 6.18.0Psalm 6.18.0@536dd6236b39a5115385b0307b42d6d1ad431a02 next: 7.0.0-beta22 |
Enforced | phpdoc_advanced_fallback_non_empty_array.php:49: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray expects non-empty-array<array-key, mixed>, but array<never, never> provided [InvalidArgument]
|
| mago | 1.50.0mago 1.50.0 | Enforced | phpdoc_advanced_fallback_non_empty_array.php:49: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray`: expected `non-empty-array<array-key, mixed>`, but possibly received `array{}`. [possibly-invalid-argument]
|
| mir | 0.78.0mir 0.78.0 | Enforced | phpdoc_advanced_fallback_non_empty_array.php:49: InvalidArgument: Argument $value of acceptsNonEmptyArray() expects 'non-empty-array', got 'array{}' [MIR0201]
|
| phpantom | 0.10.0phpantom_lsp 0.10.0 | Not enforced | No diagnostics reported.
|
| intelephense | 1.18.5intelephense 1.18.5 | Not enforced | No diagnostics reported.
|
| phpactor | 2026.06.23.0Phpactor 2026.06.23.0 | Not enforced | No diagnostics reported.
|
| phpy | 1.0.19274phpy 1.0.19274 | Not enforced | No diagnostics reported.
|
| qodana | 262.9437.196Qodana 262.9437.196 | Not enforced | No diagnostics reported.
|
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Unrecognized ⚠ 1 false positive | phpdoc_advanced_fallback_non_empty_array.php:30: param $value miss matched with phpdoc type <<array<mixed>>> [funcParamTypeMissMatch] phpdoc_advanced_fallback_non_empty_array.php:37: param $value miss matched with phpdoc type <<non-empty-array<mixed>>> [funcParamTypeMissMatch]
Expectation diffLine 30: Unexpected errors ["param $value miss matched with phpdoc type <<array<mixed>>> [funcParamTypeMissMatch]"] |
| steins | 0.1.8steins 0.1.8 (2026-09-21 revision 76306a9) | Enforced | phpdoc_advanced_fallback_non_empty_array.php:49: argument [] to acceptsNonEmptyArray() violates declared @param non-empty-array<mixed> $value — declared contract violation [phpdoc.param-mismatch]
|
| phpstan-strict | 2.2.15PHPStan - PHP Static Analysis Tool 2.2.15 | Enforced | phpdoc_advanced_fallback_non_empty_array.php:49: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray expects non-empty-array<mixed>, array{} given.
|
| psalm-next | 7.0.0-beta22Psalm 7.0.0-beta22@de27e5724ee5997a1e3baee4d394ca6f4e46eba0 | Enforced | phpdoc_advanced_fallback_non_empty_array.php:49: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray expects non-empty-array<array-key, mixed>, but array<never, never> provided [InvalidArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray;
/**
* `non-empty-array`
*
* An array with at least one element. It is the array counterpart of
* `non-empty-string`, and the only member of this group whose base type can be
* written natively, so the parameter can carry `array` in the signature and the
* refinement in the docblock at once.
*
* References:
* - PHPStan TypeNodeResolver `non-empty-array` resolves to array&NonEmptyArrayType
*/
/**
* @return non-empty-array<mixed>
*/
function returnsNonEmptyArray(): array // T: non-empty-array<mixed>
{
return [1]; // V
}
/**
* @param array<mixed> $value
*/
function acceptsArray(array $value): void
{
}
/**
* @param non-empty-array<mixed> $value
*/
function acceptsNonEmptyArray(array $value): void // T: non-empty-array<mixed>
{
}
// A `non-empty-array` value always satisfies a native `array` parameter.
acceptsArray(returnsNonEmptyArray()); // V
// One element is enough, whatever it is.
acceptsNonEmptyArray([1]); // V
acceptsNonEmptyArray([null]); // V
// The empty array is not.
acceptsNonEmptyArray([]); // E?: [] is not a non-empty-array