ReflectionType::allowsNull

(PHP 7)
Checks if null is allowed
public bool ReflectionType::allowsNull ( void )

Checks whether the parameter allows NULL.

Returns:

TRUE if NULL is allowed, otherwise FALSE

Examples:
ReflectionType::allowsNull() example
<?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 something similar to:

bool(false)
bool(true)
See also:

ReflectionType::isBuiltin() -

ReflectionType::__toString() -

ReflectionParameter::getType() -

doc_php
2016-02-24 16:13:51
Comments
Leave a Comment

Please login to continue.