Re:PHP solves problems. Oh, and you can program with it too
by dr42 on Friday June 29, 2012 @07:56PM
(#4179789)
This may appear 'retarded' until you understand how type conversion works. Then those examples are perfectly logical and expected. PHP has === if you want to disable the type conversion in the conditional operator.
[ Parent
| on HN ]
Re:PHP solves problems. Oh, and you can program with it too
by jules on Friday June 29, 2012 @10:09PM
(#4180182)
Knowing how something works does not make it a good idea. I see this attitude a lot: if you've mastered something complicated, it seems so logical and inevitable. I had this attitude myself once when I only knew PHP. But then you discover that PHP is not god given or a natural phenomenon. A human put each and every behavior in a programming language. Some choices are better than others. Significantly worse choices were made in PHP than in e.g. Python. Therefore new programmers should learn a language like Python, not PHP. It's a waste of time to learn the intricacies of things that ended up that way due to a bad decision or even by accident. Note that Python is far from perfect too, but it's one of the least bad to start with.
Re:PHP solves problems. Oh, and you can program with it too
by 10098 on Friday June 29, 2012 @08:02PM
(#4179814)
I know about ===. I do understand how type conversion works. I just don't think that it works "correctly". Converting "0" to 0 implicitly seems completely illogical to me. A string is not a number.
Re:PHP solves problems. Oh, and you can program with it too
by dr42 on Saturday June 30, 2012 @03:28AM
(#4181007)
"a string is not a number"
Well then use ===, but when a string contains numbers then php will do the type conversion for you. It's a convenience.
It may not work correctly by your definition but it's pretty intuitive and useful the way it is.