Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

get_debug_type

Returns the type name of a value the way it is written in code.

Syntax

get_debug_type(mixed $value): string

Parameters

ParameterTypeDescription
$valuemixedAny value.

Return value

stringThe name of the type or class.

Examples

Compared with gettype():

<?php
 
echo gettype(1.5), ' / ', get_debug_type(1.5), "\n";
echo gettype(null), ' / ', get_debug_type(null), "\n";
echo gettype(new ArrayObject()), ' / ', get_debug_type(new ArrayObject());

Output:

double / float
NULL / null
object / ArrayObject

Notes

The function is handy for error messages: it returns int, float, null and the class name rather than integer, double, NULL, object.

See also

  • gettype — Returns the name of a value's type.
  • get_class — Returns the class name of an object.
  • var_dump — Prints the type and the value — for debugging.

In the tutorial

  • Data types — The main PHP data types — strings, numbers, booleans, arrays and null.

Thanks for reading!

Donate to the site — we work hard for you.