PhpStorm doesn’t give me any error for this function block
/** * @param array $foo * @return string */ public function test(array $foo): string { return (string)$foo; }
Despite casting array to string will result in a notice.
Similarly, there’s no error for this
/** * @param array|string $foo * @return int|false */ public function test($foo) { return strpos($foo, 'foo'); }
Though strpos
only accepts a string and $foo
may be an array.
phpstan will catch these issues, but it’d be nice if PhpStorm could raise them while writing. I haven’t seen a way to integrate phpstan, either.
submitted by /u/Zurahn
[link] [comments]