« ReflectionType
ReflectionType::__toString »

ReflectionType::allowsNull

(PHP 7, PHP 8)

ReflectionType::allowsNull — null が許されるかをチェックする

説明

public function ReflectionType::allowsNull(): bool

引数が null を許容するかをチェックします。

パラメータ

この関数にはパラメータはありません。

戻り値

null が許容されるなら true を、そうでないなら false を返します。

例

例1 ReflectionType::allowsNull() の例

<?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());

上の例の出力は以下となります。

bool(false)
bool(true)

参考

関連キーワード:
ReflectionType   allowsNull   チェック   reflectionParams   getType   toString   許容   someFunction   param   reflectionFunc   dump   stdClass   ReflectionFunction   getParameters   参考   ReflectionNamedType   isBuiltin   組み込み   ReflectionParameter
関連する関数・ページ:
reflectiontype.tostring   class.reflectiontype   reflectionnamedtype.isbuiltin   reflectionparameter.gettype   class.reflectionnamedtype   class.reflectionuniontype