← All results

List shape support for positional destructuring and indexed access

Group: Arrays and shapes · Category: phpdoc · File: arrays_list_shape_destructuring.php

References: - Psalm list shape syntax - python-typing tuple-style positional element inspiration

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 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/8 of the expected violations reported
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Partly enforced (4/8) reported Lv.5+
arrays_list_shape_destructuring.php:48: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesInt expects int, bool given. [identifier=argument.type] [reported-from-level=5]
arrays_list_shape_destructuring.php:49: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesString expects string, bool given. [identifier=argument.type] [reported-from-level=5]
arrays_list_shape_destructuring.php:50: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesBool expects bool, int given. [identifier=argument.type] [reported-from-level=5]
arrays_list_shape_destructuring.php:54: Parameter #1 $list of function Conformance\Tests\ArraysListShapeDestructuring\inspectListShape expects array{bool, float, string, int}, array{true, 1.5, 2, 'x'} given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
arrays_list_shape_destructuring.php:48: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesInt expects int, bool given. [identifier=argument.type]
arrays_list_shape_destructuring.php:49: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesString expects string, bool given. [identifier=argument.type]
arrays_list_shape_destructuring.php:50: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesBool expects bool, int given. [identifier=argument.type]
arrays_list_shape_destructuring.php:54: Parameter #1 $list of function Conformance\Tests\ArraysListShapeDestructuring\inspectListShape expects array{bool, float, string, int}, array{true, 1.5, 2, 'x'} given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 4/8 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Partly enforced (4/8)
arrays_list_shape_destructuring.php:48: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\takesInt expects int, but bool provided [InvalidScalarArgument]
arrays_list_shape_destructuring.php:49: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\takesString expects string, but bool provided [InvalidScalarArgument]
arrays_list_shape_destructuring.php:50: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\takesBool expects bool, but int provided [InvalidScalarArgument]
arrays_list_shape_destructuring.php:54: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\inspectListShape expects list{bool, float, string, int}, but list{true, float(1.5), 2, 'x'} provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 4/8 of the expected violations reported
mago 1.46.0mago 1.46.0 Partly enforced (4/8)
arrays_list_shape_destructuring.php:48: Invalid argument type for argument #1 of `Conformance\Tests\ArraysListShapeDestructuring\takesInt`: expected `int`, but found `bool`. [invalid-argument]
arrays_list_shape_destructuring.php:49: Invalid argument type for argument #1 of `Conformance\Tests\ArraysListShapeDestructuring\takesString`: expected `string`, but found `bool`. [invalid-argument]
arrays_list_shape_destructuring.php:50: Invalid argument type for argument #1 of `Conformance\Tests\ArraysListShapeDestructuring\takesBool`: expected `bool`, but found `int`. [invalid-argument]
arrays_list_shape_destructuring.php:54: Possible argument type mismatch for argument #1 of `Conformance\Tests\ArraysListShapeDestructuring\inspectListShape`: expected `list{bool, float, string, int}`, but possibly received `list{true, float(1.5), int(2), string('x')}`. [possibly-invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 4/8 of the expected violations reported
mir 0.70.1mir 0.70.1 Partly enforced (4/8)
arrays_list_shape_destructuring.php:48: InvalidArgument: Argument $value of takesInt() expects 'int', got 'bool' [MIR0201]
arrays_list_shape_destructuring.php:49: InvalidArgument: Argument $value of takesString() expects 'string', got 'bool' [MIR0201]
arrays_list_shape_destructuring.php:50: InvalidArgument: Argument $value of takesBool() expects 'bool', got 'int' [MIR0201]
arrays_list_shape_destructuring.php:54: InvalidArgument: Argument $list of inspectListShape() expects 'array{0: bool, 1: float, 2: string, 3: int}', got 'array{0: true, 1: 1.5, 2: 2, 3: "x"}' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 4/8 of the expected violations reported
phpantom 0.9.0phpantom_lsp 0.9.0 Partly enforced (3/8)
arrays_list_shape_destructuring.php:48: Argument 1 ($value) expects int, got bool [type_mismatch_argument]
arrays_list_shape_destructuring.php:49: Argument 1 ($value) expects string, got bool [type_mismatch_argument]
arrays_list_shape_destructuring.php:50: Argument 1 ($value) expects bool, got int [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 3/8 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Partly enforced (3/8)
arrays_list_shape_destructuring.php:48: Expected type 'int'. Found 'bool'. [P1006]
arrays_list_shape_destructuring.php:49: Expected type 'string'. Found 'bool'. [P1006]
arrays_list_shape_destructuring.php:50: Expected type 'bool'. Found 'int'. [P1006]
  • Recognition: spelling resolved
  • Enforcement: 3/8 of the expected violations reported
phpy 0.2.0phpy 0.2.0 Partly enforced (1/8)
arrays_list_shape_destructuring.php:48: Argument '1' passed to Conformance\Tests\ArraysListShapeDestructuring\takesInt() is expected to be of type int, bool given
  • Recognition: spelling resolved
  • Enforcement: 1/8 of the expected violations reported
qodana 262.8665.325Qodana 262.8665.325 Unrecognized
arrays_list_shape_destructuring.php:32: Argument type does not match the declared [PhpDocSignatureInspection]
  • Recognition: spelling not resolved — reported on declaration line(s) 32
  • Enforcement: 0/8 of the expected violations reported — incidental, since the spelling was not resolved
noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Unrecognized
arrays_list_shape_destructuring.php:34: param $list miss matched with phpdoc type <<list{bool, float, string, int}>> [funcParamTypeMissMatch]
arrays_list_shape_destructuring.php:43: potential null array access in parameter value of function Conformance\Tests\ArraysListShapeDestructuring\takesBool [notNullSafetyFunctionArgumentArrayDimFetch]
arrays_list_shape_destructuring.php:44: potential null array access in parameter value of function Conformance\Tests\ArraysListShapeDestructuring\takesFloat [notNullSafetyFunctionArgumentArrayDimFetch]
arrays_list_shape_destructuring.php:45: potential null array access in parameter value of function Conformance\Tests\ArraysListShapeDestructuring\takesString [notNullSafetyFunctionArgumentArrayDimFetch]
arrays_list_shape_destructuring.php:46: potential null array access in parameter value of function Conformance\Tests\ArraysListShapeDestructuring\takesInt [notNullSafetyFunctionArgumentArrayDimFetch]
arrays_list_shape_destructuring.php:48: potentially not safe call in function Conformance\Tests\ArraysListShapeDestructuring\takesInt signature of param value [notSafeCall]
arrays_list_shape_destructuring.php:49: potential null array access in parameter value of function Conformance\Tests\ArraysListShapeDestructuring\takesString [notNullSafetyFunctionArgumentArrayDimFetch]
arrays_list_shape_destructuring.php:50: potential null array access in parameter value of function Conformance\Tests\ArraysListShapeDestructuring\takesBool [notNullSafetyFunctionArgumentArrayDimFetch]
  • Recognition: spelling not resolved — reported on declaration line(s) 34
  • Enforcement: 7/8 of the expected violations reported — incidental, since the spelling was not resolved
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Partly enforced (1/8)
arrays_list_shape_destructuring.php:54: argument [true, 1.5, 2, 'x'] to inspectListShape() violates declared @param list{bool, float, string, int} $list — declared contract violation [phpdoc.param-mismatch]
  • Recognition: spelling resolved
  • Enforcement: 1/8 of the expected violations reported
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Partly enforced (4/8)
arrays_list_shape_destructuring.php:48: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesInt expects int, bool given. [identifier=argument.type]
arrays_list_shape_destructuring.php:49: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesString expects string, bool given. [identifier=argument.type]
arrays_list_shape_destructuring.php:50: Parameter #1 $value of function Conformance\Tests\ArraysListShapeDestructuring\takesBool expects bool, int given. [identifier=argument.type]
arrays_list_shape_destructuring.php:54: Parameter #1 $list of function Conformance\Tests\ArraysListShapeDestructuring\inspectListShape expects array{bool, float, string, int}, array{true, 1.5, 2, 'x'} given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 4/8 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Partly enforced (4/8)
arrays_list_shape_destructuring.php:48: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\takesInt expects int, but bool provided [InvalidScalarArgument]
arrays_list_shape_destructuring.php:49: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\takesString expects string, but bool provided [InvalidScalarArgument]
arrays_list_shape_destructuring.php:50: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\takesBool expects bool, but int provided [InvalidScalarArgument]
arrays_list_shape_destructuring.php:54: Argument 1 of Conformance\Tests\ArraysListShapeDestructuring\inspectListShape expects list{bool, float, string, int}, but list{true, float(1.5), 2, 'x'} provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 4/8 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\ArraysListShapeDestructuring;

/**
 * List shape support for positional destructuring and indexed access.
 *
 * References:
 * - Psalm list shape syntax
 * - python-typing tuple-style positional element inspiration
 */

function takesBool(bool $value): void
{
}

function takesFloat(float $value): void
{
}

function takesString(string $value): void
{
}

function takesInt(int $value): void
{
}

/**
 * @param list{bool, float, string, int} $list
 */
function inspectListShape(array $list): void // T: list{bool, float, string, int}
{
    [$a, $b, $c, $d] = $list;

    takesBool($a);
    takesFloat($b);
    takesString($c);
    takesInt($d);

    takesBool($list[0]); // E?: some tools do not preserve list shape indexed access precisely
    takesFloat($list[1]); // E?: some tools do not preserve list shape indexed access precisely
    takesString($list[2]); // E?: some tools do not preserve list shape indexed access precisely
    takesInt($list[3]); // E?: some tools do not preserve list shape indexed access precisely

    takesInt($a); // E?: destructured element 0 should stay bool
    takesString($list[0]); // E?: indexed element 0 should stay bool
    takesBool($list[3]); // E?: indexed element 3 should stay int
}

inspectListShape([true, 1.5, 'x', 2]); // V
inspectListShape([true, 1.5, 2, 'x']); // E?: call-site list shape should preserve positional element types