ReflectionParameter::allowsNull

(PHP 5, PHP 7)

ReflectionParameter::allowsNullChecks if null is allowed

설명

public bool ReflectionParameter::allowsNull ( void )

Checks whether the parameter allows NULL.

Warning

이 함수는 현재 문서화 되어있지 않습니다; 인수 목록만을 제공합니다.

인수

이 함수는 인수가 없습니다.

반환값

TRUE if NULL is allowed, otherwise FALSE

참고

add a note add a note

User Contributed Notes 1 note

up
15
Geoffrey LAURENT
10 years ago
The allowsNull method look if arguments have a type.
If a type is defined, null is allowed only if default value is null.

<?php
function myfunction ( $param ) {
   
}

echo (new
ReflectionFunction("myfunction"))->getParameters()[0]->allowsNull() ? "true":"false";

?>

Result : true

<?php
function myfunction ( stdClass $param ) {
   
}

echo (new
ReflectionFunction("myfunction"))->getParameters()[0]->allowsNull() ? "true":"false";

?>

Result : false

<?php
function myfunction ( stdClass $param = null ) {
   
}

echo (new
ReflectionFunction("myfunction"))->getParameters()[0]->allowsNull() ? "true":"false";
?>

Result : true
To Top