is_callable

is_callable(mixed $value, bool $syntax_only = false, string &$callable_name = null): bool

Verifies whether a value can be called as a function in the current scope (a closure, a function-name string, or an [object, method] array).

C C23

C23
#include <stdio.h>

typedef int (*fn_ptr)(void);

int answer(void) {
    return 42;
}

int main(void) {
    fn_ptr f = answer;
    fn_ptr g = NULL;
    printf("%d %d\n", f != NULL, g != NULL);
    return 0;
}
Output
1 0

C++ C++26

C++26
#include <iostream>
int answer() {
    return 42;
}
int main() {
    int (*f)() = answer;
    int (*g)() = nullptr;
    std::cout << std::boolalpha << (f != nullptr) << " " << (g != nullptr) << "\n";
    return 0;
}
Output
true false

C# v11.0.100

v11.0.100
Func<int> f = () => 42;
object notCallable = 42;
Console.WriteLine($"{f is Delegate} {notCallable is Delegate}");
Output
True False

Go v1.27.4

v1.27.4
package main

import (
    "fmt"
    "reflect"
)

func answer() int {
    return 42
}

func main() {
    fmt.Println(reflect.ValueOf(answer).Kind() == reflect.Func,
        reflect.ValueOf(42).Kind() == reflect.Func)
}
Output
true false

Java v27.0.1

v27.0.1
import java.util.concurrent.Callable;

public class Main {
    public static void main(String[] args) {
        Callable<Integer> f = () -> 42;
        Object notCallable = 42;
        System.out.println((f instanceof Callable) + " " + (notCallable instanceof Callable));
    }
}
Output
true false

JavaScript v26.13.1

v26.13.1
console.log([typeof (() => 1) === "function", typeof 42 === "function", typeof "strlen" === "function"]);
Output
[ true, false, false ]

PHP v8.6.0

v8.6.0
echo json_encode([is_callable(fn() => 1), is_callable("strlen"), is_callable(42)]);
Output
[true,true,false]

Python v3.15.2

v3.15.2
print([callable(lambda: 1), callable(42), callable("len")])
Output
[True, False, False]

Rust v1.99.1

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

fn answer() -> i32 {
    42
}

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

TypeScript v26.13.1

v26.13.1
const xs: unknown[] = [() => 1, 42, "strlen"];
console.log(xs.map((x) => typeof x === "function"));
Output
[ true, false, false ]

Language differences

C: no runtime type system — idiomatically tests function pointers against null: non-NULL means callable.

C++: no runtime type system — function pointers against null; modern C++ can constrain at compile time with the std::invocable concept.

C#: the typed alternative — is Delegate.

Go: the typed alternative — reflect.Kind() == reflect.Func.

Java: the typed alternative — instanceof Callable (functional interfaces).

JavaScript: uses typeof x === "function" (classes are functions, instances are not).

PHP: is_callable is the widest of all — beyond closures, a built-in/user function's name string ("strlen", second column true) and an [object, "method"] array both count as callable (the historical callback carriers), $syntax_only = true checks syntax without consulting scope, and a third by-ref argument hands back the canonical callable name.

Python: callable() only accepts objects implementing __call__ — the string "len" is not callable (false), len itself is.

Rust: types are known at compile time, so at runtime only fn pointers can be probed via Any::is::<fn() -> i32>() downcasting.

TypeScript: same as JS — typeof x === "function".