Following code gives 'Unnecessary type casting' warning:
(int) ($foo[0] ?? 0)
But it's true only for second part of statement.
PHPStorm version is 2018.1.2
Plugin version is 3.0.1
Thanks for report @t-kanstantsin
Confirm this bug.
Will check, thank you for reporting.
Can confirm, was just about to report the same issue, only for (bool) instead of (int).
same here.
The plugin thinks that the variable will always have the type of the value after ??.
Doesn't have to be a constant.
function foo(string $x, $y) {
$z = $y ?? $x;
return (string)$z;
}
For myself: when about to report, run possible values discovery and skip reporting for ?? (PhpStorm types resolvers is not yet efficient for ??).
Fixed
Most helpful comment
Fixed