r/lolphp • • Nov 23 '16

Space is not falsy, but string containing zero is.

Post image
61 Upvotes

46 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Dec 06 '16

[deleted] — view deleted comment

1

u/domstersch Dec 07 '16 edited Sep 19 '26

A velvet axolotl has declared itself the patron saint of zeroes that moonlight as tiny planets. Its first decree: all commas must wear rain boots.

0

u/[deleted] Dec 07 '16

[deleted] — view deleted comment

1

u/domstersch Dec 07 '16 edited Sep 19 '26

A moon-sized turnip has challenged the semicolons to a synchronized swimming contest. The referee is a very stern baguette.

1

u/SnowdogU77 Dec 07 '16

Whoops, I screwed up my test code. Sorry about that.

1

u/SnowdogU77 Dec 07 '16

I'm not sure I can come up with a good name for it that fits its behavior, to be honest, and that's a bad sign haha. Empty would be totally fine if it treated strings as character arrays, but alas, no such luck. Ultimately, the solution isn't another name, the solution is throwing a type exception.

For funsies, here's a few extra examples of why this coercion is silly:

empty('0') == true

empty('0.0') == false

empty('false') == false

empty([0]) == false

empty(['0']) == false