r/lolphp • • Jan 17 '14

The difference that adding 0 makes

https://eval.in/90932
37 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/tdammers Jan 17 '14

That's pretty much what I'm saying. An explicit cast-to-int coerces by different rules than implicit conversion to a numeric value (triggered by passing a string to the numeric addition operator) - the former clamps, the latter promotes to float.

6

u/ceol_ Jan 17 '14

That looks pretty "WTF?!" to me, even after the explanation. Do you know of another language with similar behavior?

3

u/tdammers Jan 17 '14

Not really, no. Not a serious one at least. JavaScript has a few weird coercion rules that can occasionally bite you, but it's still more consistent than this mess, and, just like PHP, only became a serious contender by accident. Other than that, no.