4 ms·
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 di
by dr42 14y ago
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.
- 10098 14y agoI 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.
- dr42 14y ago"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.
- jules 14y agoKnowing 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.