← All results

A reversed-key array literal passed to a list{...} parameter

Group: Cross-analyzer regressions · Category: regression · File: regressions_reversed_literal_list_param.php

[1 => 'x', 0 => 'y'] is not a list at runtime — array_is_list() returns false because the keys appear out of order. Passing it where a list{string, string} is required should be rejected, yet analyzers diverge: per the cross-tool survey (#14939) Phan and Psalm reject the literal while PHPStan and Mago accept it. The rejection is anchored in two different places depending on the tool: at the call site that passes the literal, or at the @param that declares the contract it breaks. Both name the same violation, so both lines carry the expectation. Reference: phpstan#14939

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 Pass
regressions_reversed_literal_list_param.php:32: Argument 1 ($list) is [1=>'x',0=>'y'] of type array{1:'x',0:'y'} but \Conformance\Tests\RegressionsReversedLiteralListParam\takesTwoList() takes list<mixed> defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/regressions_reversed_literal_list_param.php:25 [PhanTypeMismatchArgument]
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Pass
regressions_reversed_literal_list_param.php:32: Argument 1 of Conformance\Tests\RegressionsReversedLiteralListParam\takesTwoList expects list{string, string}, but parent type array{0: 'y', 1: 'x'} provided [ArgumentTypeCoercion]
mago 1.46.0mago 1.46.0 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
mir 0.70.1mir 0.70.1 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
phpantom 0.9.0phpantom_lsp 0.9.0 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
intelephense 1.18.5intelephense 1.18.5 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
phpy 0.2.0phpy 0.2.0 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
qodana 262.8665.325Qodana 262.8665.325 Pass
regressions_reversed_literal_list_param.php:23: Argument type does not match the declared [PhpDocSignatureInspection]
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Fail
regressions_reversed_literal_list_param.php:25: param $list miss matched with phpdoc type <<list{string, string}>> [funcParamTypeMissMatch]
Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Pass
regressions_reversed_literal_list_param.php:32: argument [1 => 'x', 0 => 'y'] to takesTwoList() violates declared @param list{string, string} $list — declared contract violation [phpdoc.param-mismatch]
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Pass
regressions_reversed_literal_list_param.php:32: Argument 1 of Conformance\Tests\RegressionsReversedLiteralListParam\takesTwoList expects list{string, string}, but parent type array{0: 'y', 1: 'x'} provided [ArgumentTypeCoercion]

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\RegressionsReversedLiteralListParam;

/**
 * A reversed-key array literal passed to a `list{...}` parameter.
 *
 * `[1 => 'x', 0 => 'y']` is not a list at runtime — `array_is_list()` returns false
 * because the keys appear out of order. Passing it where a `list{string, string}` is
 * required should be rejected, yet analyzers diverge: per the cross-tool survey (#14939)
 * Phan and Psalm reject the literal while PHPStan and Mago accept it.
 *
 * The rejection is anchored in two different places depending on the tool: at the call
 * site that passes the literal, or at the `@param` that declares the contract it breaks.
 * Both name the same violation, so both lines carry the expectation.
 *
 * Reference: https://github.com/phpstan/phpstan/discussions/14939
 */

/**
 * @param list{string, string} $list // E[reversed_literal+]: the reversed-key literal must be rejected; blaming the declared contract is one valid anchor
 */
function takesTwoList(array $list): void // E<noverify>: NoVerify cannot evaluate the list{string, string} param type
{
    echo $list[0] . $list[1];
}

function caller(): void
{
    takesTwoList([1 => 'x', 0 => 'y']); // E[reversed_literal+]: the reversed-key literal must be rejected; blaming the call site is the other valid anchor (#14939)
}