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
Variable $_SERVER on left side of ?? always exists and is not nullable.
However, this line of code exists for a reason: some people have test code or test code that sets $_SERVER to null. See https://3v4l.org/t1PTW for proof that this is possible.
This is a hard issue to tackle correctly and practically. Apparently you can set these global variables to anything: https://3v4l.org/8H9ap
So ideally we should make them just mixed because it's possible they might be anything.
But if you're in a codebase that doesn't do anything weird like this, they're going to be array<string, mixed>. So complaining that you're passing mixed into array after such a fix would be annoying for most people.
We could also suppress some errors reported to these global variables when rechecking their type, but it's hard to do such a thing consistently without changing type of these variables.
I'm going to keep this open but I'd say the best course of action is to ignore this kind of error - "hey, I know what I'm doing, I'm going to ignore this here".
Bug report
In PHPUnit, I have this line of code:
PHPStan wrongfully complains about this line:
However, this line of code exists for a reason: some people have test code or test code that sets
$_SERVER
tonull
. See https://3v4l.org/t1PTW for proof that this is possible.Code snippet that reproduces the problem
https://phpstan.org/r/fa40be63-50df-4254-86e8-d02f26654e49
Expected output
No error.
Did PHPStan help you today? Did it make you happy in any way?
Yes!
The text was updated successfully, but these errors were encountered: