Quote:
Originally Posted by MrOmega
My whole question is, if it works, why is it allowed?
|
GS2 is dynamically typed, so values are coerced based on whatever type they need to be. It's usually a Bad Idea™ to rely on the coercing though because it is sometimes unclear what is happening.
For example, you can check if a value exists like this:
PHP Code:
if (temp.someValue) {
// ...
}
However, what is really happening there, is
temp.someValue is being coerced to a boolean (true/false). It will actually coerce to false in the case of say,
temp.someValue = "0" or
temp.someValue = 0, thus making the if statement not work even though the value does exist.
Basically, relying on the coercing can make strange bugs crop up in edge cases that are hard to find until they actually break something. It's usually best to be explicit.
I personally dislike dynamically typed languages and think they should slowly fade out of existence.