Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

get_debug_type()

Describe a value in diagnostic messages using PHP type spelling.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

get_debug_type(mixed $value): string

Describe a value in diagnostic messages using PHP type spelling. An object reports its actual class name. An open resource reports its kind in parentheses and a closed resource has a distinct label, which helps diagnose an unexpectedly closed stream. This class-name rule applies to named classes. Anonymous classes receive a diagnostic label such as class@anonymous or stdClass@anonymous, different from get_class.

Signature

get_debug_type(mixed $value): string

Example output

["int","stdClass","resource (stream)","resource (closed)","class@anonymous","stdClass@anonymous"]

Examples

<?php
$stream = fopen("php://memory","r");
$types = [get_debug_type(1), get_debug_type(new stdClass()), get_debug_type($stream)];
fclose($stream); $types[] = get_debug_type($stream);
$types[] = get_debug_type(new class {});
$types[] = get_debug_type(new class extends stdClass {});
echo json_encode($types);

Result

["int","stdClass","resource (stream)","resource (closed)","class@anonymous","stdClass@anonymous"]

Sources