변수처리 get_debug_type

(PHP 8)

get_debug_type — 디버깅에 적합한 방식으로 변수의 유형 이름을 가져옵니다.


설명

get_debug_type(mixed $value): string

PHP 변수 value의 확인된 이름을 반환합니다. 이 함수는 객체를 클래스 이름으로, 리소스를 리소스 유형 이름으로, 스칼라 값을 유형 선언에서 사용되는 일반 이름으로 확인합니다.

이 함수는 역사적 이유로 존재하는 것보다 실제 사용법과 더 일치하는 유형 이름을 반환한다는 점에서 gettype()과 다릅니다.


매개변수

value
유형이 검사되는 변수입니다.

반환 값

반환된 문자열에 가능한 값은 다음과 같습니다.

Type + State Return Value Notes
null "null" -
Booleans (true or false) "bool" -
Integers "int" -
Floats "float" -
Strings "string" -
Arrays "array" -
Resources "resource (resourcename)" -
Resources (Closed) "resource (closed)" 예: fclose로 닫힌 후의 파일 스트림.
Objects from Named Classes 네임스페이스를 포함한 클래스의 전체 이름입니다. Foo\Bar -
Objects from Anonymous Classes "class@anonymous" 익명 클래스는 $x = new class { ... } 구문을 통해 생성된 클래스입니다.

Examples

예제 #1 get_debug_type() 예제

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

위의 예는 다음과 유사한 결과를 출력합니다.

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

기타