ReflectionType::allowsNull
PHP function
Edit on GitHub ✎
(PHP 7, PHP 8)
Checks if null is allowed
Description
ReflectionType::allowsNull(): bool
Checks whether the parameter allows null.
Parameters Parameters
Return Values
true if null is allowed, otherwise false
Examples
ReflectionType::allowsNull example
php
<?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());The above example will output:
output
bool(false)
bool(true)See Also
ReflectionNamedType::isBuiltinReflectionType::__toStringReflectionParameter::getType