ReflectionType::allowsNull

(PHP 7)

ReflectionType::allowsNullChecks if null is allowed

说明

public ReflectionType::allowsNull ( void ) : bool

Checks whether the parameter allows NULL.

参数

此函数没有参数。

返回值

TRUE if NULL is allowed, otherwise FALSE

范例

Example #1 ReflectionType::allowsNull() example

<?php
function someFunction(string $paramStdClass $param2 null) {}

$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams $reflectionFunc->getParameters();

var_dump($reflectionParams[0]->getType()->allowsNull());
var_dump($reflectionParams[1]->getType()->allowsNull());

以上例程的输出类似于:

bool(false)
bool(true)

参见