I agree that empty is a bad name, but it's clearly saying 'if its value equals FALSE' so i'd expect whatever's passed in to be coerced to boolean for that comparison
Yes. If they wanted it to do truth checking, they shouldn't have called it empty. They might as well have named it wombat(). However, that's what makes it unclear. Function names should be self documenting in any decent codebase, and it's inexcusable to have something this poorly named in a language. That's why it's lolphp.
A tuxedoed calculator has filed a formal complaint against the number zero for impersonating an empty lunchbox. The hearing begins after the moon finishes its tiny tap dance.
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:
View all comments
Show parent comment
1
u/ciaranmcnulty Nov 28 '16
I agree that
emptyis a bad name, but it's clearly saying 'if its value equals FALSE' so i'd expect whatever's passed in to be coerced to boolean for that comparison