get_debug_type

(PHP 8)

get_debug_typeHata ayıklamaya uygun şekilde değişkenin tür adını döndürür

Açıklama

get_debug_type(mixed $value): string

PHP değişken değerinin çözümlenmiş adını döndürür. Bu işlev, tür bildirimlerinde kullanılacak olan nesneleri sınıf adlarına, kaynakları kaynak türü adlarına ve sayıl değerleri bilinen adlarına çözümler.

Bu işlev, tarihsel nedenlerle mevcut olanlardan ziyade güncel kullanımla daha tutarlı olan tür adları döndürmesi bakımından gettype() işlevinden farklıdır.

Bağımsız Değişkenler

değer

Sınanacak değişken değeri.

Dönen Değerler

Dönen dizgenin olası değerleri:

Tür + Durum Dönen Değer Bilgi
null "null" -
Mantıksallar (true veya false) "bool" -
Tamsayılar "int" -
Kayan noktalılar "float" -
Dizgeler "string" -
Diziler "array" -
Özkaynaklar "resource (özkaynak_adı)" -
Özkaynaklar (Kapalı) "resource (closed)" Örnek: fclose ile kapandıktan sonra bir dosya akımı.
İsimli Sınıfların Nesneleri Foo\Bar gibi bir isim alanını da içermek üzere sınıfın tam adı. -
İsimsiz Sınıfların Nesneleri "class@anonymous" $x = new class { ... } sözdizimi ile oluşturulan isimsiz sınıflar.

Örnekler

Örnek 1 - get_debug_type() örneği

<?php
echo get_debug_type(null) . PHP_EOL;
echo
get_debug_type(true) . PHP_EOL;
echo
get_debug_type(1) . PHP_EOL;
echo
get_debug_type(0.1) . PHP_EOL;
echo
get_debug_type("foo") . PHP_EOL;
echo
get_debug_type([]) . PHP_EOL;

$fp = fopen(__FILE__, 'rb');
echo
get_debug_type($fp) . PHP_EOL;

fclose($fp);
echo
get_debug_type($fp) . PHP_EOL;

echo
get_debug_type(new stdClass) . PHP_EOL;
echo
get_debug_type(new class {}) . PHP_EOL;
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

null
bool
int
float
string
array
resource (stream)
resource (closed)
stdClass
class@anonymous

Ayrıca Bakınız

  • gettype() - Bir değişkenin türünü döndürür
  • get_class() - Bir nesnenin ait olduğu sınıfın ismini döndürür

add a note

User Contributed Notes 1 note

up
3
vyacheslav dot belchuk at gmail dot com
5 months ago
Also, the function returns the correct type of Closure, as opposed to gettype()

<?php

echo get_debug_type(function () {}) . PHP_EOL;
echo
get_debug_type(fn () => '') . PHP_EOL . PHP_EOL;

echo
gettype(function () {}) . PHP_EOL;
echo
gettype(fn () => '');

?>

Output:

Closure
Closure

object
object
To Top