is_int

is_int(mixed $value): bool

Finds whether a variable is of integer type.

C C23

C23
#include <stdio.h>

#define is_int(x) _Generic((x), int: 1, default: 0)

int main(void) {
    int i = 42;
    double d = 42.0;
    printf("%d %d %d\n", is_int(i), is_int(d), is_int("42"));
    return 0;
}
Output
1 0 0

C++ C++26

C++26
#include <iostream>
#include <type_traits>
int main() {
    int i = 42;
    double d = 42.0;
    std::cout << std::boolalpha << std::is_same_v<decltype(i), int> << " "
              << std::is_same_v<decltype(d), int> << "\n";
    return 0;
}
Output
true false

C# v11.0.100

v11.0.100
object[] xs = { 42, "42", 42.0 };
foreach (object x in xs) {
    Console.WriteLine(x is int);
}
Output
True
False
False

Go v1.27.4

v1.27.4
package main

import "fmt"

func main() {
    xs := []any{42, "42", 42.0}
    for _, x := range xs {
        _, ok := x.(int)
        fmt.Println(ok)
    }
}
Output
true
false
false

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        Object[] xs = { 42, "42", 42.0 };
        for (Object x : xs) {
            System.out.println(x instanceof Integer);
        }
    }
}
Output
true
false
false

JavaScript v26.13.1

v26.13.1
console.log([Number.isInteger(42), Number.isInteger("42"), Number.isInteger(42.0)]);
Output
[ true, false, true ]

PHP v8.6.0

v8.6.0
echo json_encode([is_int(42), is_int("42"), is_int(42.0)]);
Output
[true,false,false]

Python v3.15.2

v3.15.2
print([isinstance(x, int) for x in [42, "42", 42.0]])
Output
[True, False, False]

Rust v1.99.1

v1.99.1
use std::any::Any;

fn main() {
    let xs: Vec<Box<dyn Any>> = vec![Box::new(42i32), Box::new("42"), Box::new(42.0f64)];
    for x in &xs {
        println!("{}", x.is::<i32>());
    }
}
Output
true
false
false

TypeScript v26.13.1

v26.13.1
const xs: (number | string)[] = [42, "42", 42.0];
console.log(xs.map((x) => Number.isInteger(x)));
Output
[ true, false, true ]

Language differences

C: in static contexts _Generic dispatches at compile time.

C++: in static contexts std::is_same_v dispatches at compile time.

C#: the idiomatic counterpart on dynamic containers is x is int.

Go: the idiomatic counterpart on dynamic containers is the type assertion x.(int).

Java: the idiomatic counterpart on dynamic containers is x instanceof Integer.

JavaScript: numbers make no int/float distinction — 42.0 === 42, so Number.isInteger(42.0) is true (the third column), the biggest behavioral gap versus PHP; also note Number.isInteger("42") is false even though Number("42") converts — checking and converting are different operations.

PHP: the classic divergence is the literal 42.0 — is_int (aliases is_integer, is_long) checks the type strictly, and a numeric-looking "42" string does not count; everywhere else integers and floats are distinct types, so 42.0 is false.

Python: the trap — bool subclasses int, so isinstance(True, int) is true; for true integer semantics exclude booleans first with isinstance(x, bool) or use type(x) is int.

Rust: the idiomatic counterpart on dynamic containers is Any::is::<i32>().

TypeScript: same as JS — numbers make no int/float distinction.