Bug report
Code snippet that reproduces the problem
<?php declare(strict_types = 1);
/**
* @param array{foo?: ?string} $data
*/
function foobar(array $data): void
{
if (key_exists('foo', $data) && !is_null($data['foo'])) {
var_dump($data['foo']);
}
}
# key_exists() VS array_key_exists()
/**
* @param array{foo?: ?string} $data
*/
function foobar2(array $data): void
{
if (array_key_exists('foo', $data) && !is_null($data['foo'])) {
var_dump($data['foo']);
}
}
https://phpstan.org/r/611006d0-f84e-4616-bc0b-c80defe6abbd
Expected output
When using array_key_exists() you get no warnings, while using it's alias key_exists() does return an warning:
Offset 'foo' does not exist on array{foo?: string|null}.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan is awesome!