CakeFest 2024: The Official CakePHP Conference

ReflectionType::allowsNull

(PHP 7, PHP 8)

ReflectionType::allowsNullnull が許されるかをチェックする

説明

public 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)

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top