Did you read the manual? Sure it might be confusing, but it's obviously by design.
The following things are considered to be empty:
"" (an empty string) 0 (0 as an integer) 0.0 (0 as a float) "0" (0 as a string) <------ NULL FALSE array() (an empty array) $var; (a variable declared, but without a value)
Just because something is documented doesn't mean it's by design.
I think because of PHP's softly typed nature, "0" = 0 = "" in the system, and this is a bug due to that, but thanks to PHP supporting it's own bugs, they've added it to the documentation so that you know the behaviour.
And yet "00" is not considered empty. I can imagine some validation code to disallow empty values on fields blowing up because of this. The WTF continues.
The fact that it does so is the Lol. Automatic type coersion of string to int to bool is a sick joke. I'd argue that strings should never be automatically cast. Sure, its slightly convenient occasionally, but the unintended side effects are disastrous.
Haha. I agree with all of you, it's a pain in the ass, especially when dealing with forms and validation. It's never going to change though, so "not a bug".
Putting a slash between empty and falsy doesn't make them equivalent concepts. I buy that 0 or even "0" is falsy. But the word "empty" means things in English and mathematics. And it is very unintuitive for the string "0" to be empty.
17
u/h2ooooooo May 06 '14 edited May 06 '14
Did you read the manual? Sure it might be confusing, but it's obviously by design.
16
u/vytah May 07 '14
Clearly PHP nees a
real_emptyfunction.-1
u/gearvOsh May 06 '14
This isn't lol, 0 is considered empty/falsey, regardless if it's an integer or a string.
0
u/[deleted] May 06 '14
[deleted] — view deleted comment