Skip to content

Array destructuring does not trigger undefined index #3267

@iluuu1994

Description

@iluuu1994

Feature request

https://phpstan.org/r/7a9008c1-c923-4c04-8bbb-9886b5a40bdc

/**
 * @return array{int, int}
 */
function size(): array
{
    return [10, 20];
}

class HelloWorld {
	public function bar(): void {
		$x = size()[2]; // Offset 2 does not exist on array(int, int).
		[$width, $height, $depth] = size(); // Nothing
	}
}

Interestingly Psalm has the exact same bug missing feature https://psalm.dev/r/c335c7713c :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions