Reflection ReflectionType::allowsNull
(PHP 7, PHP 8)
ReflectionType::allowsNull — null이 허용되는지 확인
설명
public ReflectionType::allowsNull(): bool
매개변수가 null
을 허용하는지 확인합니다.
매개변수
이 함수에는 매개변수가 없습니다.
반환 값
null
이 허용되면 true
, 그렇지 않으면 false
Examples
예제 #1 ReflectionType::allowsNull() 예제
<?php
function someFunction(string $param, StdClass $param2 = null) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
var_dump($reflectionParams[0]->getType()->allowsNull());
var_dump($reflectionParams[1]->getType()->allowsNull());
위의 예는 다음을 출력합니다.
bool(false) bool(true)
기타
- ReflectionNamedType::isBuiltin() - 내장형인지 확인
- ReflectionType::__toString() - To string
- ReflectionParameter::getType() - 매개변수의 유형을 가져옵니다.