ReflectionParameter::allowsNull

(PHP 5)

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
11 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