← 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.10Phan 6.0.10 php-ast version 1.1.3 PHP version used to run Phan: 8.5.11 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.3.1PHPStan - PHP Static Analysis Tool 2.3.1 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
psalm 6.20.0Psalm 6.20.0@804f03c0c183d149fcd4b8c7c0c9b3fbf836d34c
next: 7.0.0-rc2
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.57.0mago 1.57.0 Pass
regressions_reversed_literal_list_param.php:32: Invalid argument type for argument #1 of `Conformance\Tests\RegressionsReversedLiteralListParam\takesTwoList`: expected `list{string, string}`, but found `array{0: string('y'), 1: string('x')}`. [invalid-argument]
mir 0.87.0mir 0.87.0 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
phpantom 0.11.1phpantom_lsp 0.11.1 Pass
regressions_reversed_literal_list_param.php:32: Argument 1 ($list) expects list{string, string}, got array{1: 'x', 0: 'y'} (keys are not in list order) [type_mismatch_argument]
intelephense 1.18.5intelephense 1.18.5 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
phpactor 2026.10.07.0Phpactor 2026.10.07.0 Fail

No diagnostics reported.

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

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
qodana 262.10968.76PhpStorm 262.10968.76 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.8steins 0.1.8 (2026-09-21 revision 76306a9) 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.3.1PHPStan - PHP Static Analysis Tool 2.3.1 Fail

No diagnostics reported.

Expectation diff
Lines 23, 32: Expected error (tag reversed_literal)
psalm-next 7.0.0-rc2Psalm 7.0.0-rc2@20339e3fe5b8d03bcd8061030eb2a83ad50e5783 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)
}