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: phpstan#14939| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.11Phan 6.0.11 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.5PHPStan - PHP Static Analysis Tool 2.3.5 | Fail | No diagnostics reported. Expectation diffLines 23, 32: Expected error (tag reversed_literal) |
| psalm | 6.20.9Psalm 6.20.9@f67170ac3c3b931f5088681e21d6c8babc601c08 next: 7.0.4 |
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.59.0mago 1.59.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.91.0mir 0.91.0 | Fail | No diagnostics reported. Expectation diffLines 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 diffLines 23, 32: Expected error (tag reversed_literal) |
| phpactor | 2026.10.07.0Phpactor 2026.10.07.0 | Fail | No diagnostics reported. Expectation diffLines 23, 32: Expected error (tag reversed_literal) |
| phpy | 1.0.19490phpy 1.0.19490 | Fail | No diagnostics reported. Expectation diffLines 23, 32: Expected error (tag reversed_literal) |
| qodana | 262.11879.104PhpStorm 262.11879.104 | 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 diffLines 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.5PHPStan - PHP Static Analysis Tool 2.3.5 | Fail | No diagnostics reported. Expectation diffLines 23, 32: Expected error (tag reversed_literal) |
| psalm-next | 7.0.4Psalm 7.0.4@fa5b1f6e665cb743838ffd865b8fc96207f9409f | 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] |
<?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)
}