Skip to content

False positive: If condition is always false. #2420

@iluuu1994

Description

@iluuu1994

https://phpstan.org/r/eae81481-04ee-44d2-8ee8-e573625aa034

class HelloWorld
{
	const CONFIG = [
		0 => ['foo' => false],
		1 => ['foo' => false],
	];
	
	public function sayHello(int $key): void
	{
		$config = self::CONFIG[$key]['foo'] ?? true;
		
		if ($config) {
			print 'Foo';
		}
	}
}

If condition is always false.

This only happens when the CONFIG is multidimensional. This here works:

https://phpstan.org/r/0d649821-d7b9-446b-99a5-acd0e3a66002

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions