(PHP 5, PHP 7, PHP 8)
ReflectionParameter::allowsNull — Checcs if null is allowed
Checcs whether the parameter allows
null
.
This function has no parameters.
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