Hacker News new | past | comments | ask | show | jobs | submit login

I really would find this "deeply unintuitive" if I decided to try PHP with only intellisense as a reference. But by their very definition a language's idioms are not obvious. And this isn't my first rodeo, so I'd know that. And I'd read a little--just a little--before i jumped in.

Concepts and algorithms are universal. Operators and keywords are not.

Luckily, this is such a common need when learning a language that this information is kept all together in a tidy tabular way.

Because without it, I'd probably whip up an index.php and write something like print 'Welcome, ' + user.firstName;, get frustrated by parse errors, then by runtime errors, then write some impassioned comment about how deeply unintuitive it is to require prefixed variables and how using a dot for concatenation instead of a plus sign or ampersand is simply logic defying.

And that same table that explains concatenation and scope resolution is also going to give me a simple treatment on the == and === operators in this weakly typed language.

PHP is not an elegant language and given the choice, I'd nearly always prefer to be writing something else. But I took my time to respond to this because there's enough wrong with PHP that we don't need to resort to hyperbole to bash it.




I mostly agree, except that I don't think any treatment explaining

  NULL != "0" == false == NULL == 0 == "false" == true
is going to be simple.


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.


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.


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?


That isn't legal PHP.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: