W3docs

is_long()

The is_long() function in PHP is used to check whether a variable is of the integer data type. It returns true if the variable is an integer and false

Introduction

is_long() is a built-in PHP function that checks whether a variable holds a value of the integer data type. It returns true if the variable is an integer and false otherwise.

The key thing to understand is that is_long() is an exact alias of is_int(): both names call the same underlying function and behave identically. This page explains where the is_long() name comes from, how it behaves, and why you should generally prefer is_int() in new code.

Why the name "is_long"?

In PHP's C source code, the integer type is represented internally by a C long. Because of that history, PHP exposes three interchangeable names for the very same integer check:

  • is_int() — the canonical, recommended name.
  • is_integer() — an alias kept for readability.
  • is_long() — an alias that mirrors the internal C type name.

All three are still available in current PHP (including PHP 8.x), and all three return the same result for the same input. The PHP manual lists is_long() and is_integer() as aliases of is_int() and recommends is_int() for clarity.

Basic Syntax

is_long($variable); // identical to is_int($variable)

The $variable parameter is the value to test. The function returns true only for an actual integer value, with no type coercion — numeric strings and floats return false.

Example Usage

Here is_long() is used to test three different variables:

php— editable, runs on the server
bool(true)
bool(false)
bool(false)

Only $var1 is a true integer. The numeric string "10" and the float 3.14 both return false, because is_long() checks the actual type and never converts the value first. Swapping is_long() for is_int() here would produce exactly the same output — that is what "alias" means.

Filtering values by type

Because it returns a boolean, is_long() works directly as a callback for functions like array_filter(). This is handy for keeping only the genuine integers from a mixed array:

php— editable, runs on the server
Array
(
    [0] => 10
    [3] => 40
)

array_filter() keeps only the real integers, dropping the numeric string "20" and the float 30.5. Note that the original array keys (0 and 3) are preserved, not renumbered.

Important Notes

  • Alias of is_int(): is_long() has no behavior of its own. There is no separate "long" type in PHP distinct from int; the name simply reflects the internal C representation.
  • Still available, but not preferred: is_long() works in current PHP, but the manual recommends is_int() for readability. Many style guides and static-analysis tools flag the alias.
  • No type coercion: like is_int(), it returns false for numeric strings ("123") and whole-number floats (5.0). To accept those, use is_numeric() or filter_var($var, FILTER_VALIDATE_INT).

Best Practices

Prefer is_int() in new code

is_int(), is_integer(), and is_long() are interchangeable, so pick one and be consistent. The community convention is is_int() — it is the shortest, the clearest, and the name the documentation uses.

Avoid redundant comparisons

Since the function already returns a boolean, wrapping its result in a strict comparison (=== true) is unnecessary. Just write if (is_int($var)).

  • is_int() — the canonical, recommended integer check.
  • is_integer() — another readable alias of is_int().
  • is_numeric()true for integers, floats, and numeric strings.
  • is_float() — checks for floating-point values.
  • is_string() — checks for string values.

Conclusion

is_long() is simply an alternative name for is_int(). It performs a strict, coercion-free integer check and behaves identically to its better-known counterpart. Because the alias adds no functionality and can confuse readers, use is_int() in new code and reserve is_long() for understanding older codebases that still rely on the name.

Practice

Practice
Which of the following statements about the PHP 'is_long' function is true?
Which of the following statements about the PHP 'is_long' function is true?
Was this page helpful?