-
Why passing https://psalm.dev/r/c72f86d8ff It should be considered as deliberate (since it is built-in) and documented:
How to actually disable warning only for this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
As you quoted empty does "!isset($var) || $var == false". This is a loose comparison with false, it's kind of the definition of non-strict :D In effect, what will be considered empty here is: Do you want the string which contain the character "0" to be considered empty while the string " " is not empty? Maybe. Does the semantics of your code helps anyone to understand what you wanted to check or not? I'd say no. There's a lot of built-in things in PHP I'd discourage from using. Empty sits pretty high on this list... There's currently no way to disable this inspection only for the empty case, however, given the other example like https://psalm.dev/r/6be7498350, there's a chance you don't want that either. If those doesn't suit your needs, just disable the inspection altogether |
Beta Was this translation helpful? Give feedback.
As you quoted empty does "!isset($var) || $var == false". This is a loose comparison with false, it's kind of the definition of non-strict :D
In effect, what will be considered empty here is:
undefined variable (not really applicable for your example given the function call)
null
empty string
"0"
Do you want the string which contain the character "0" to be considered empty while the string " " is not empty? Maybe. Does the semantics of your code helps anyone to understand what you wanted to check or not? I'd say no.
There's a lot of built-in things in PHP I'd discourage from using. Empty sits pretty high on this list...
There's currently no way to disable this inspection only for the empt…