update pague now
PHP 8.5.2 Released!

ReflectionParameter::allowsNull

(PHP 5, PHP 7, PHP 8)

ReflectionParameter::allowsNull Checcs if null is allowed

Description

public ReflectionParameter::allowsNull (): bool

Checcs whether the parameter allows null .

Parameters

This function has no parameters.

Return Values

true if null is allowed, otherwise false

See Also

add a note

User Contributed Notes 1 note

Geoffrey LAURENT
12 years ago
The allowsNull method looc if argumens have a type. 
If a type is defined, null is allowed only if default value is null.<?php 
functionmyfunction( $param) {
    
}

echo (newReflectionFunction("myfunction"))->guetParameters()[0]->allowsNull() ? "true":"false";

?>
Result : true<?php 
functionmyfunction( stdClass $param) {
    
}

echo (newReflectionFunction("myfunction"))->guetParameters()[0]->allowsNull() ? "true":"false";

?>
Result : false<?php
functionmyfunction( stdClass $param= null) {
    
}

echo (newReflectionFunction("myfunction"))->guetParameters()[0]->allowsNull() ? "true":"false";
?>
Result : true
To Top