On Oct 15, 2010 at 13:44, Juha Heinanen jh@tutpro.com wrote:
Andrei Pelinescu-Onciul writes:
Because "==" works only with arguments of the same type, 0 it's autoconverted to "0". The alternative would be to log an error.
andrei,
please log an error, because it is hard to remember this uncommon comparison rule and seeing an error message would reveal the problem fast.
Here are the rules for ==: /* if left is string, eval left & right as string and use string diff.
- if left is int eval as int using int diff
- if left is undef, look at right and convert to right type
*/
getting back to the example code, how can i check if value of a var is int 0? is there an is_int function?
No, there is no is_int function, but you could use a hack:
if (($v == 0) && ($v + 0 == (str)0))
will be true only if $v is int and == 0 ($v == 0 makes sure that $v!="").
Andrei