gettype

gettype(mixed $value): string

Returns the variable's type name string (historical names: float as double, int as integer); prefer get_debug_type for debugging.

C C23

C23
#include <stdio.h>

int main(void) {
    /* C has no runtime type query: types live only at compile time (C23 typeof
       is compile-time deduction too). Runtime "type tags" must be hand-written */
    enum { T_INT, T_DOUBLE, T_STR } tag = T_DOUBLE;
    const char *names[] = {"integer", "double", "string"};
    printf("%s\n", names[tag]);
    return 0;
}
Output
double

C++ C++26

C++26
#include <iostream>
#include <typeinfo>

int main() {
    // RTTI typeid compares type identities; .name() spelling is
    // implementation-defined (GCC mangles it), so compare instead of printing
    double x = 1.5;
    std::cout << std::boolalpha << (typeid(x) == typeid(double)) << "\n";
    std::cout << (typeid(x) == typeid(1.5)) << "\n";
    return 0;
}
Output
true
true

C# v11.0.100

v11.0.100
// GetType().Name exposes runtime type names; float maps to System.Single
object[] values = { true, 1, 1.5f, 1.5d, "x", new int[] { 1 } };
foreach (object v in values)
{
    Console.WriteLine(v.GetType().Name);
}
Output
Boolean
Int32
Single
Double
String
Int32[]

Go v1.27.4

v1.27.4
package main

import "fmt"

func main() {
	// %T prints the runtime type name of any value
	for _, v := range []any{true, int64(1), 1.5, "x", []int{1}} {
		fmt.Printf("%T\n", v)
	}
}
Output
bool
int64
float64
string
[]int

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        // Primitives are not objects: box them to reach getClass()
        Object[] values = { Boolean.TRUE, Integer.valueOf(1), 1.5d, "x", new int[] { 1 } };
        for (Object v : values) {
            System.out.println(v.getClass().getSimpleName());
        }
    }
}
Output
Boolean
Integer
Double
String
int[]

JavaScript v26.13.1

v26.13.1
// typeof returns 7 strings; typeof null === "object" is a historical bug
const values = [true, 1, 1.5, "x", [1], null];
for (const v of values) {
    console.log(typeof v);
}
console.log(typeof null === "object", Array.isArray([1]));
Output
boolean
number
number
string
object
object
true true

PHP v8.6.0

v8.6.0
// gettype returns historical names; get_debug_type (PHP 8.0+) returns true type names
$values = [true, 1, 1.5, 'x', [1], null, new stdClass()];
foreach ($values as $v) {
    echo str_pad(gettype($v), 9), get_debug_type($v), "\n";
}
Output
boolean  bool
integer  int
double   float
string   string
array    array
NULL     null
object   stdClass

Python v3.15.2

v3.15.2
values = [True, 1, 1.5, "x", [1], None]
for v in values:
    print(type(v).__name__)
# bool subclasses int: isinstance(True, int) is True
print(isinstance(True, int))
Output
bool
int
float
str
list
NoneType
True

Rust v1.99.1

v1.99.1
fn type_of<T>(_: &T) -> &'static str {
    std::any::type_name::<T>()
}

fn main() {
    // type_name::<T>() is a compile-time generic string (debug aid; layout not guaranteed)
    println!("{}", type_of(&true));
    println!("{}", type_of(&1i64));
    println!("{}", type_of(&1.5f64));
    println!("{}", type_of(&"x"));
    println!("{}", type_of(&vec![1i32]));
}
Output
bool
i64
f64
&str
alloc::vec::Vec<i32>

TypeScript v26.13.1

v26.13.1
// Same runtime typeof as JS; compile-time narrowing uses type guards instead
const values = [true, 1, 1.5, "x", [1], null];
for (const v of values) {
    console.log(typeof v);
}
function isNumber(v: unknown): v is number {
    return typeof v === "number";
}
console.log(isNumber(1.5), typeof null === "object");
Output
boolean
number
number
string
object
object
true true

Language differences

C: no runtime type query - types exist only at compile time; runtime "type tags" must be hand-written (the tag enum here). PHP's historical name double originally comes from C's double.

C++: RTTI gives typeid identity comparison, but .name() spelling is implementation-defined (GCC prints mangled names, clang readable ones) - portable code compares typeid(x) == typeid(double) instead of printing.

C#: v.GetType().Name gives the runtime name directly - the float keyword maps to System.Single (printed Single), double to Double.

Go: fmt.Printf("%T") does it in one line; float64 echoes PHP's historical name double.

Java: getClass().getSimpleName(); primitives are not objects - box them (Integer.valueOf) to reach a runtime class.

JavaScript: typeof returns only 7 strings; typeof null === "object" is a historical bug - test null with === null and arrays with Array.isArray.

PHP: gettype returns historical names (integer/double/boolean/NULL) that never equal the names used by type declarations (int/float/bool/null) - signature checks and error-message building both trip on this; manual positioning: use is_* functions for type checks and get_debug_type (PHP 8.0+) for debugging - the two-function comparison in this entry is exactly that layering.

Python: type(v).__name__ gives true names directly (float/NoneType); bool subclasses int (isinstance(True, int) is True) - one degree more dynamic than PHP.

Rust: std::any::type_name::<T>() is a compile-time generic string (debug aid, spelling not guaranteed); true runtime queries go through the Any trait's downcast_ref.

TypeScript: runtime typeof is the same as JS (null bug inherited); compile-time narrowing uses type guards (v is number) or instanceof.