News for hackers. Stuff that matters.
Re:PHP WTF: A PHP Annoyance Posted Every Day by prodigal_erik on Friday June 19, 2009 @03:50PM (#665733)
I mostly agree, except that I don't think any treatment explaining

  NULL != "0" == false == NULL == 0 == "false" == true
is going to be simple.
Re:PHP WTF: A PHP Annoyance Posted Every Day by encoderer on Friday June 19, 2009 @05:13PM (#665825)
Sure it is:

To avoid implicit type coercion, use the identity operators === and !==.

Of course, the code you posted doesn't parse without adding parens. And when you do, it becomes much more obvious what it's doing and why.

Re:PHP WTF: A PHP Annoyance Posted Every Day by prodigal_erik on Saturday June 20, 2009 @05:33PM (#666846)
Sorry, I meant that as a bunch of compares that are mutually inconsistent, not one big expression. And "don't use ==" isn't really a solution until you persuade the runtime and every major library author to stop using it.
Re:PHP WTF: A PHP Annoyance Posted Every Day by encoderer on Saturday June 20, 2009 @09:38PM (#667028)
I don't get your point. Nobody has said "don't use equality." Equality is the right choice nearly all the time.

I've worked on some very large web apps (mostly C#, Python and PHP) and I can't recall ever really being foiled by php's implicit casting.

Just out of genuine curiousity, can you share an example where this caused a problem that you had to debug?

And if php implicit casting did somehow cause you problems, surely it was fixed by changing it from equality to identity?

So in summary... this could potentially cause a bug, but probably not, and if it does, it would be a consistent bug, and it would be fixed by a single keystroke.

Why, again, are we talking about this?

Re:PHP WTF: A PHP Annoyance Posted Every Day by ars on Friday June 19, 2009 @06:01PM (#665868)
That isn't legal PHP.