Signature
is_long(mixed $value): boolPurpose
is_long() answers one question: is the value you passed an integer? It returns true only when the value's type is int. According to the PHP manual, is_long() is an alias of is_int(). Both names call the same function and behave identically. The name long comes from the C type that integers historically mapped to, but PHP has no separate long type. New code usually uses is_int(), because that name matches the int type declaration. You will still see is_long() in older code bases.
Signature
Parameters and defaults
$value: any value at all. There is no default, so the argument is required. Scalars, arrays, objects,nulland resources are all accepted.
Return value and failure cases
The function returns true when $value has type int and false for every other type. It does not throw for unusual input and does not emit warnings. A value of the wrong type is not an error, it is just a false result.
The check looks at the type, not at the content. The string "15" looks like a number, but it is a string, so the result is false. The float 3.0 has no fractional part, but it is still a float, so the result is false.
Example 1: which types count as integers
The loop below runs several kinds of values through is_long() and prints a readable label for each result.
$samples = [
'int' => 42,
'negative' => -7,
'zero' => 0,
'float' => 3.0,
'numeric string' => '15',
'bool' => true,
'null' => null,
];
foreach ($samples as $label => $value) {
echo $label, ': ', is_long($value) ? 'true' : 'false', "\n";
}int: true negative: true zero: true float: false numeric string: false bool: false null: false
Only the first three entries are integers. Booleans and null are never treated as integers by this function, even though PHP can convert them to integers in arithmetic.
Example 2: filtering and the alias relationship
Because the function returns a boolean and takes one argument, you can pass its name as a callback. array_filter() keeps the elements for which the callback returns true. The second line shows that the alias gives the same answers as is_int().
$data = [1, '2', 3.5, 4, [5]];
$ints = array_values(array_filter($data, 'is_long'));
echo json_encode($ints), "\n";
echo json_encode(array_map('is_long', $data) === array_map('is_int', $data)), "\n";[1,4] true
The filtered list holds only the real integers. The strict comparison of the two result arrays is true because the two names are the same function.
Example 3: results of arithmetic
The type of a computed value is not always what the numbers suggest. This example checks several expressions.
$results = [
'intdiv' => intdiv(10, 2),
'slash' => 10 / 2,
'slash fraction' => 10 / 4,
'round' => round(2.4),
'cast' => (int) round(2.4),
'overflow' => PHP_INT_MAX + 1,
];
foreach ($results as $label => $value) {
echo $label, ': ', is_long($value) ? 'true' : 'false', "\n";
}intdiv: true slash: true slash fraction: false round: false cast: true overflow: false
intdiv() always yields an integer. The / operator yields an integer when both operands are integers and the division is exact, otherwise a float. round() always returns a float, so you must cast it if you need an integer. Adding one to PHP_INT_MAX leaves the integer range, so PHP produces a float.
Edge cases
- Numeric strings:
"42","0x1A"and"1e3"are all strings, sois_long()returnsfalse. If you need to validate user input such as form data, usefilter_var()withFILTER_VALIDATE_INTor check withctype_digit()first. - Floats with whole values:
5.0is a float. Convert it with(int)only if you are sure that truncation is acceptable. - Booleans and null:
true,falseandnullreturnfalse. - Integer limits: values beyond the platform's integer range become floats, and
is_long()reports them as non-integers. - Objects and arrays: these return
falseand are never inspected.
Common mistakes
- Expecting
is_long("123")to betrue. Input from forms, query strings and most text sources arrives as strings, so you must validate or convert it before relying on a type check. - Assuming that
is_long()means a bigger integer thanis_int(). They are the same function. - Using the result of
round(),floor()orceil()directly. These return floats, sois_long()returnsfalsefor them. - Using
is_long()to test for any number. Useis_numeric()when strings with numeric content are allowed, oris_int()together withis_float()when you need real numbers only. - Mixing the two names in the same project without a reason. Pick one, preferably
is_int(), to keep the code consistent.
Related functions
is_int(): the primary name of this function.is_integer(): another alias of the same check.is_float(): tests for the float type.is_numeric(): accepts numbers and numeric strings.filter_var(): validates and converts text input.gettype()andget_debug_type(): report the type name of a value.
Recap
is_long() is an alias of is_int() with the signature is_long(mixed $value): bool. It returns true only for values whose type is int. Numeric strings, whole-number floats, booleans and null all return false. Convert or validate input first when you expect text, and prefer the name is_int() in new code.
Tested examples
$samples = [
'int' => 42,
'negative' => -7,
'zero' => 0,
'float' => 3.0,
'numeric string' => '15',
'bool' => true,
'null' => null,
];
foreach ($samples as $label => $value) {
echo $label, ': ', is_long($value) ? 'true' : 'false', "\n";
}
int: true negative: true zero: true float: false numeric string: false bool: false null: false
$data = [1, '2', 3.5, 4, [5]];
$ints = array_values(array_filter($data, 'is_long'));
echo json_encode($ints), "\n";
echo json_encode(array_map('is_long', $data) === array_map('is_int', $data)), "\n";
[1,4] true
$results = [
'intdiv' => intdiv(10, 2),
'slash' => 10 / 2,
'slash fraction' => 10 / 4,
'round' => round(2.4),
'cast' => (int) round(2.4),
'overflow' => PHP_INT_MAX + 1,
];
foreach ($results as $label => $value) {
echo $label, ': ', is_long($value) ? 'true' : 'false', "\n";
}
intdiv: true slash: true slash fraction: false round: false cast: true overflow: false