$productid = "0x4zz5";
print $productid + 4;
If printing "8" is your idea of a working interpretation of that code, then PHP is the language for you.If not, then PHP doesn't work. End of story.
$productid = "0x4zz5";
print $productid + 4;
If printing "8" is your idea of a working interpretation of that code, then PHP is the language for you.If not, then PHP doesn't work. End of story.
Implicit type conversion is evil, and I don't see how PHP's sin of favouring string -> number over number -> string is any worse than, say:
// Javascript
console.log(+(+!![]+(+[]+[]))); // outputs the number 10
Or: // C, Java
float celsius, fahrenheit1, fahrenheit2;
celsius = 100;
fahrenheit1 = celsius * 9 / 5 + 32;
fahrenheit2 = 9 / 5 * celsius + 32;
assert(fahrenheit1 == 212); // OK
assert(fahrenheit2 == 212); // Oops! It's 132. What happened?harshreality argued that, because PHP's implicit type conversion leads to weird behaviour, "PHP doesn't work. End of story."
In that case, nearly every widely used language (with the possible exception of Python 3) "doesn't work. End of story." That's not a very interesting or useful story to tell.
As I said earlier, I agree that implicit type-conversion is evil. But if I refused to use flawed tools...
Of course, it is better to manually convert.
It's the computer equivalent of a bozo worker who does something random everytime they don't know how to do their job, and then tries to hide any consequences while whistling innocently.
The whole total function has something that it's expected to do, some value that it returns in the end - and if it can't do that then any returned value is useless and wrong anyway; and automatic, silent type conversion is the worst possible choice of action, since it not only doesn't work, returning a value that you didn't intend (as other options); but in addition makes the actual bug hard to find and potentially corrupts a lot of stored data before you find the bug.
So, you'd probably be pretty ornery too when other people had more discipline to use the language without shooting their foot and were also employing it successfully. You'd probably want to make assumptions, and word hard to belittle them. Insult them.
And they'll talk about beauty. And zen. And wonder, and joy in a language. And they'll gloss over the major problems that it suffers from. They'll imagine all is well. And they'll try and tell you that nothing good can come from the tool they once used to shoot themselves in the foot.
Just walk away. Because you still have two feet.
print $productid . 4;You missed the problem as well. Don't ask for trouble by creating broken situations.
I wish I could use static typing too, but when I can't I use vars that are somewhat intuitive.