Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
My understanding is that non-empty strings and non-zero numbers get cast to true in a boolean context. Likewise empty strings and 0 get cast to false.
So I find it completely logical that "0" is cast to true and 0 is cast to false in the boolean context. It is possible that this doesn't explicitly happen in Ruud's code, but the effect is the same. Ruud may wish to comment on this.
I hope we can all agree that context is what determines the way a variable is cast.
Here's another interesting result of casting the RHS to the vartype of the LHS when checking for equality.
Code:
If 1 = 1.1
"This is another example"
EndIf
This one is even more insidious as they are both numbers. I know, I know the LHS is an integer and the RHS is a double. However going back to my assertion before that both that sides of the equality should be converted to the data type that retains the most information, I suggest that in this equality context they should both be cast to double and then checked.
If my suggestion was followed then 0 wouldn't equal "a" and 1 wouldn't equal 1.1, but 1.1 would equal "1.1" as before, which seems to me to be logical.