← All results

non-empty-array

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

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

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.10Phan 6.0.10 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 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]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
phpstan 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 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-rules
phpdoc_advanced_fallback_non_empty_array.php:49: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedFallbackNonEmptyArray\acceptsNonEmptyArray expects non-empty-array<mixed>, array{} given.
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
psalm 6.20.0Psalm 6.20.0@804f03c0c183d149fcd4b8c7c0c9b3fbf836d34c
next: 7.0.0-rc2
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]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
mago 1.57.0mago 1.57.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]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
mir 0.87.0mir 0.87.0 Enforced
phpdoc_advanced_fallback_non_empty_array.php:49: ArgumentTypeCoercion: Argument $value of acceptsNonEmptyArray() expects 'non-empty-array', got 'array{}' — coercion may fail at runtime [MIR0225]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
phpantom 0.11.1phpantom_lsp 0.11.1 Enforced
phpdoc_advanced_fallback_non_empty_array.php:49: Argument 1 ($value) expects non-empty-array<mixed>, got array{} [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
phpactor 2026.10.07.0Phpactor 2026.10.07.0 Not enforced

No diagnostics reported.

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

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported
qodana 262.10968.76PhpStorm 262.10968.76 Widened to array

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/1 of the expected violations reported

Notes: Checked as plain `array` (its messages expect `mixed[]`): `[]` passes, and anything that is not an array is rejected, exactly as for `@param array`.

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]
  • Recognition: spelling not resolved — reported on declaration line(s) 37
  • Enforcement: 0/1 of the expected violations reported — incidental, since the spelling was not resolved
  • False positives: line(s) 30
Expectation diff
Line 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]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
phpstan-strict 2.3.1PHPStan - PHP Static Analysis Tool 2.3.1 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.
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported
psalm-next 7.0.0-rc2Psalm 7.0.0-rc2@20339e3fe5b8d03bcd8061030eb2a83ad50e5783 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]
  • Recognition: spelling resolved
  • Enforcement: 1/1 of the expected violations reported

Source

<?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