get_debug_type

get_debug_type(mixed $value): string

Returns a variable's real type name (PHP 8.0+): float/int/stdClass, contrasted with gettype's historical double/integer - always prefer it for debugging.

C C23

C23
#include <stdio.h>

int main(void) {
    /* C's types live entirely at compile time - there is no runtime
       type name to ask for. The only runtime question is sizeof. */
    printf("%zu\n", sizeof(1.5)); /* 8: the double's storage size */
    printf("%zu\n", sizeof(1));   /* 4: sizeof(int) */
    printf("%zu\n", sizeof("x")); /* 2: array of 2 chars, NUL included */
    return 0;
}
Output
8
4
2

C++ C++26

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

int main() {
    // typeid gives runtime names, but they are implementation-defined:
    // gcc/clang emit Itanium-mangled short names (d = double, i = int)
    std::cout << typeid(1.5).name() << "\n"; // d
    std::cout << typeid(1).name() << "\n";   // i
    std::cout << typeid("x").name() << "\n"; // A2_c: array of 2 chars
    return 0;
}
Output
d
i
A2_c

C# v11.0.100

v11.0.100
object[] values = { 1.5, 1, "x", new int[] { } };
foreach (object v in values) {
    Console.WriteLine(v.GetType().Name); // GetType(): runtime query on the instance
}
Console.WriteLine(typeof(double).Name); // typeof: compile-time query on the type
Output
Double
Int32
String
Int32[]
Double

Go v1.27.4

v1.27.4
package main

import "fmt"

func main() {
	fmt.Printf("%T\n", 1.5)              // float64 - Go names the machine type
	fmt.Printf("%T\n", 1)                // int
	fmt.Printf("%T\n", "x")              // string
	fmt.Printf("%T\n", []int{1})         // []int
	fmt.Printf("%T\n", map[string]int{}) // map[string]int
	fmt.Printf("%T\n", struct{ A int }{}) // struct { A int }: anonymous layout too
}
Output
float64
int
string
[]int
map[string]int
struct { A int }

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        Object[] values = {1.5, 1, "x", new int[]{}, null};
        for (Object v : values) {
            // getClass(): runtime query; primitives have no object to ask
            System.out.println(v == null ? "null" : v.getClass().getSimpleName());
        }
        System.out.println(double.class.getName()); // class literal for primitives
    }
}
Output
Double
Integer
String
int[]
null
double

JavaScript v26.13.1

v26.13.1
console.log(typeof 1.5);      // "number": one type for ints and floats
console.log(typeof "x");      // "string"
console.log(typeof true);     // "boolean"
console.log(typeof undefined); // "undefined"
console.log(typeof null);     // "object": the famous typeof bug
const real = (v) => Object.prototype.toString.call(v).slice(8, -1);
console.log(real(1.5)); // "Number" - the precise internal name
console.log(real(null)); // "Null"
console.log(real([1]));  // "Array"
Output
number
string
boolean
undefined
object
Number
Null
Array

PHP v8.6.0

v8.6.0
// gettype keeps the historical names; get_debug_type returns the modern ones
var_dump(gettype(1.5));        // double: a name inherited from PHP 3
var_dump(get_debug_type(1.5)); // float: the real type name
var_dump(gettype(1));          // integer
var_dump(get_debug_type(1));   // int
var_dump(get_debug_type('x')); // string
var_dump(get_debug_type(null)); // null
var_dump(get_debug_type(new stdClass())); // objects get the class name
$r = fopen('php://memory', 'r');
var_dump(get_debug_type($r));  // resources: "resource (type)"
fclose($r);
var_dump(get_debug_type($r));  // closed: "resource (closed)"
Output
string(6) "double"
string(5) "float"
string(7) "integer"
string(3) "int"
string(6) "string"
string(4) "null"
string(8) "stdClass"
string(17) "resource (stream)"
string(17) "resource (closed)"

Python v3.15.2

v3.15.2
print(type(1.5).__name__)    # float - Python never hid float behind "double"
print(type(1).__name__)      # int - arbitrary precision, not a machine word
print(type("x").__name__)    # str
print(type(None).__name__)   # NoneType
print(type([1]).__name__)    # list
print(type(len).__name__)    # builtin_function_or_method
print(type(3 + 2j).__name__) # complex
Output
float
int
str
NoneType
list
builtin_function_or_method
complex

Rust v1.99.1

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

fn main() {
    // compile-time type names: type_name is evaluated during compilation
    // and returns the full path
    println!("{}", type_name::<f64>());      // f64
    println!("{}", type_name::<i32>());      // i32
    println!("{}", type_name::<String>());   // alloc::string::String
    println!("{}", type_name::<Vec<i32>>()); // alloc::vec::Vec<i32>
}
Output
f64
i32
alloc::string::String
alloc::vec::Vec<i32>

TypeScript v26.13.1

v26.13.1
console.log(typeof 1.5);      // "number": one type for ints and floats
console.log(typeof "x");      // "string"
console.log(typeof true);     // "boolean"
console.log(typeof undefined); // "undefined"
console.log(typeof null);     // "object": the famous typeof bug
const real = (v: unknown) => Object.prototype.toString.call(v).slice(8, -1);
console.log(real(1.5)); // "Number" - the precise internal name
console.log(real(null)); // "Null"
console.log(real([1]));  // "Array"
Output
number
string
boolean
undefined
object
Number
Null
Array

Language differences

C: types exist only at compile time - there is no runtime type name to ask for, and the only runtime question is sizeof (the example answers with byte sizes); carrying "values with types" means building a tagged union yourself.

C++: typeid(...).name() is a runtime query, but the name is implementation-defined: gcc/clang print Itanium-mangled short names like d/i, MSVC prints double/int; on gcc __cxa_demangle restores a readable name.

C#: GetType().Name queries the instance (short name Int32) and typeof(T).Name queries the type - both are first-class; FullName gives the full name.

Go: %T / reflect.TypeOf prints the real type - anonymous struct layouts, generic instantiations and compound map/slice types all print truthfully; a type is a static fact, not a runtime costume.

Java: getClass().getSimpleName() works only on objects; primitives have no getClass, use the class literal double.class; array class names look like int[]; getSimpleName gives the short name, getName the full one.

JavaScript: typeof is too coarse - typeof null === "object" is a historical bug and ints/floats share number; for the precise internal name use Object.prototype.toString.call(x).slice(8, -1) (example).

PHP: gettype keeps the historical names (double/integer), while get_debug_type (8.0+) returns float/int matching type declarations; objects yield the class name, resources yield resource (type), and closed resources yield resource (closed) - always prefer get_debug_type for debugging and error messages.

Python: type(x).__name__ is the real name - Python never called float double; and in duck-typing culture exact type checks are rare anyway.

Rust: std::any::type_name::<T>() is evaluated at compile time and returns the full path (such as alloc::string::String); the docs explicitly note it is for debugging display only and its output format is not guaranteed to be stable.

TypeScript: runtime behavior matches JavaScript; there is also a compile-time typeof x type operator - same name, different thing, one typeof at the type level and one at the value level.