What are the potential pitfalls of using is_int() to check if a variable is an integer?

Using is_int() to check if a variable is an integer may not work as expected in certain cases. This function only returns true if the variable is an integer type, not if it contains an integer value. To accurately check if a variable contains an integer value, you can use is_numeric() instead. This function will return true if the variable is a number or a numeric string.

$variable = "42";

if (is_numeric($variable) && (int)$variable == $variable) {
    echo "The variable contains an integer value.";
} else {
    echo "The variable does not contain an integer value.";
}