You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There can be a scenario, where a class may either exist or not exist, e.g. because of an optional dependency or because of supporting different versions of an upstream library. In such a scenario it is typical to check with class_exists if the corresponding class exists or not.
If the class does not exist, it seems like PHPStan inflects that such class cannot be a class-string. This leads to a type error.
/** * @return list<array{string, class-string}> */publicfunctiondataProviderForTestValidCommands(): array
{
$data = [
// left out some commands here for simplicity ...// [...]
[
'migrations:execute',
ExecuteCommand::class,
],
];
// this is only available with DBAL 2.xif (class_exists(ImportCommand::class)) {
$data[] = [
'dbal:import',
ImportCommand::class,
];
}
return$data;
}
There should be no issue, as the result always holds the type list<array{string, class-string}>. However, PHPStan produces the following error on level 3:
Bug report
There can be a scenario, where a class may either exist or not exist, e.g. because of an optional dependency or because of supporting different versions of an upstream library. In such a scenario it is typical to check with
class_exists
if the corresponding class exists or not.If the class does not exist, it seems like PHPStan inflects that such class cannot be a
class-string
. This leads to a type error.Code snippet that reproduces the problem
Consider the following code, a snippet from DoctrineORMModule:
There should be no issue, as the result always holds the type
list<array{string, class-string}>
. However, PHPStan produces the following error on level 3:Expected output
I would expect PHPStan not to raise any issues here.
Did PHPStan help you today? Did it make you happy in any way?
Thank you for your great work with PHPStan! :-)
The text was updated successfully, but these errors were encountered: