is_int() and is_string() Do Not Work As Expected In PHP

is_int() returns TRUE if the variable passed in is an integer, which may sound similar to is_numeric(). However, data passed in through a form or from MySQL query, even if numeric in content, is of type string, which means that is_int() will fail. Is_numeric(), on the other hand, returns true if the variable is a number or if it is a string containing a number also. This same problem applies to is_float(), as floating-point values set from user input are typed as strings. On contrast, when numeric data passed through a form or from MySQL query, is_string() does return TRUE.

This feature makes is_int() and is_string() next to useless.


http://www.tuxradar.com/practicalphp/7/7/3

No comments:

Post a Comment

Labels