-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Summary of a problem or a feature request
For the code snippet showed below phpstan generates error:
+----------------------------------------------+
| Line | test.php |
+----------------------------------------------+
| 10 | Result of && is always false. |
+----------------------------------------------+
It seems because the type checks done are same as the types mention in docblock phpstan thinks the checks are unnecessary and will always equate to false. But due to lack of typehint PHP won't throw any error even if an argument of invalid type is passed to the method and extra check is necessary.
Code snippet that reproduces the problem
https://phpstan.org/r/9438ae1f-53d3-495d-98d5-951684ad888f
<?php declare(strict_types = 1);
class HelloWorld
{
/**
* @param array|\ArrayAccess $arg
*/
public function sayHello($arg): void
{
if (!is_array($arg) && !($arg instanceof \ArrayAccess)) {
throw new InvalidArgumentException();
}
}
}Expected output
No error shown.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels