1

What is the exact difference between gettype() and get_debug_type()?

Official documentation describes it, but too vague for me:

  • gettype(): Get the type or object name of a variable
  • get_debug_type(): Get the type of a variable
1

1 Answer 1

1

Both functions are generally used for variable debugging and to get the type of a given variable.

The main difference is:

get_debug_type() differs from gettype() in that it returns type names that are more consistent with actual usage, rather than those present for historical reasons.


gettype() returns one of the following possible string values:

  • "boolean"
  • "integer"
  • "double" (for historical reasons "double" is returned in case of a float, and not simply "float")
  • "string"
  • "array"
  • "object"
  • "resource"
  • "resource (closed)" as of PHP 7.2.0 "NULL"
  • "unknown type"

get_debug_type() returns one of the following possible string values:

Type + State Return Value
null "null"
Booleans (true or false) "bool"
Integers "int"
Floats "float"
Strings "string"
Array "array"
Resources "resource (resourcename)"
Resources (Closed) "resource (closed)"
Objects from Named Classes The full name of the class including its namespace e.g. Foo\Bar
Objects from Anonymous Classes "class@anonymous"

Sources:

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.