Signature
is_integer(mixed $value): boolPurpose
is_integer() answers one question: is the value you passed of PHP's int type? It is an alias of is_int(), so both names behave identically. Pick one and use it consistently in a codebase. The function inspects the type of the value, not its appearance, so it does not ask whether the value looks like a whole number.
Signature
Because the manual describes is_integer() as an alias of is_int(), the signature is the same as that of is_int().
Parameters and defaults
$value: any value at all. It is required and has no default. Integers, floats, strings, booleans,null, arrays, objects and resources can all be passed in.
Return value and failure cases
The function returns true when the value is of type int, and false for every other type. It does not throw for unexpected input, does not emit warnings, and does not convert the argument. There is no separate failure value, because every input produces a plain boolean.
Example 1: which types count?
Only a real integer passes. Floats, numeric strings, booleans and null do not, even when they could be converted to an integer.
$values = [42, -7, 0, 3.5, "42", true, null, [1]];
foreach ($values as $value) {
echo json_encode($value), ' => ', var_export(is_integer($value), true), "\n";
}42 => true -7 => true 0 => true 3.5 => false "42" => false true => false null => false [1] => false
Notice that "42" is a string, so it is rejected. The quotes in the JSON output make that visible.
Example 2: checking the result of a parser
filter_var() with FILTER_VALIDATE_INT returns an integer on success and false on failure. Calling is_integer() on the result is a clear way to tell the two cases apart. A parsed 0 is a valid integer but is falsy, so a plain truthiness test would wrongly treat it as a failure.
$inputs = ["15", "15.5", "abc", "-3"];
foreach ($inputs as $input) {
$parsed = filter_var($input, FILTER_VALIDATE_INT);
echo $input, ': ', is_integer($parsed) ? 'integer' : 'not integer', "\n";
}15: integer 15.5: not integer abc: not integer -3: integer
Example 3: overflow and arithmetic results
The type of an expression depends on the operation. Adding one to PHP_INT_MAX overflows into a float. Dividing with / yields an integer only when both operands are integers and the division is exact.
$max = PHP_INT_MAX;
$next = $max + 1;
echo json_encode([is_integer($max), is_integer($next), is_integer(10 / 2), is_integer(10 / 4)]);
echo "\n";[true,false,true,false]
Edge cases
- A float with no fractional part, such as
3.0, is still a float, so the result isfalse. - Numeric strings such as
"7"or"0x1A"are strings and returnfalse. true,falseandnullare never integers.- Integer overflow produces a float, which
is_integer()rejects. -0written as an integer literal is just0, which is an integer.- In a file without
strict_types, a value that was coerced when passed to a typed parameter may already be anint. Check the type at the point where you actually hold the value.
Common mistakes
- Expecting form input to pass. Request data and many text sources arrive as strings. Calling
is_integer()on them returnsfalse. Validate withfilter_var()or convert deliberately first. - Confusing it with
is_numeric().is_numeric("42")istrue, whileis_integer("42")isfalse. They answer different questions. - Treating whole floats as integers. Results of functions such as
floor()andround()are floats, sois_integer(floor(4.7))isfalse. - Mixing alias names. Using both
is_int()andis_integer()in one project works, but it makes searching and reviewing harder. - Testing truthiness instead of type. A parsed
0is falsy. When a function can returnfalseon failure, check the type rather than the value's truth.
Related functions
is_int(): the primary name of the same check.is_float(): tests for the float type.is_numeric(): accepts integers, floats and numeric strings.filter_var(): validates and converts text to an integer.intval(): converts a value to an integer instead of checking it.gettype()andget_debug_type(): report the type name.
Recap
is_integer() is a strict type check and an alias of is_int(). It takes one value of any type, never throws, and returns true only for values whose type is int. Numeric strings, whole-number floats and booleans all return false, so validate or convert input first when it may arrive in another type.
Tested examples
$values = [42, -7, 0, 3.5, "42", true, null, [1]];
foreach ($values as $value) {
echo json_encode($value), ' => ', var_export(is_integer($value), true), "\n";
}
42 => true -7 => true 0 => true 3.5 => false "42" => false true => false null => false [1] => false
$inputs = ["15", "15.5", "abc", "-3"];
foreach ($inputs as $input) {
$parsed = filter_var($input, FILTER_VALIDATE_INT);
echo $input, ': ', is_integer($parsed) ? 'integer' : 'not integer', "\n";
}
15: integer 15.5: not integer abc: not integer -3: integer
$max = PHP_INT_MAX;
$next = $max + 1;
echo json_encode([is_integer($max), is_integer($next), is_integer(10 / 2), is_integer(10 / 4)]);
echo "\n";
[true,false,true,false]