Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / PHP

get_debug_type()

Podaje typ w komunikacie diagnostycznym zgodnie z pisownią PHP.

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

Składnia

get_debug_type(mixed $value): string

Podaje typ w komunikacie diagnostycznym zgodnie z pisownią PHP. Dla obiektu zwraca nazwę klasy, dla otwartego zasobu jego rodzaj w nawiasie, a zamknięty strumień dostaje osobną etykietę. Ta reguła nazwy dotyczy klas nazwanych. Klasa anonimowa otrzymuje etykietę diagnostyczną, np. class@anonymous albo stdClass@anonymous, różną od get_class.

Sygnatura

get_debug_type(mixed $value): string

Wynik przykładu

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

Przykłady

<?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);

Wynik

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

Źródła