Skip to content

Phpstan ignores possibly undefined array offsets #7553

@ptomulik

Description

@ptomulik

Bug report

The following code should raise an error, but it passes with level 9 + strict rules.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

/**
 * @param array<mixed> $array
 * @return mixed
 */
function foo(array $array) {
	return $array['foo'];
}

https://phpstan.org/r/5347b67e-f0ad-4505-aeca-cfb074dcb3e7

Expected output

It should raise an error about possibly undefined array offset, same way as psalm does. Quite obvious.

https://psalm.dev/r/e3d927af68

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