(PHP 7, PHP 8)
ReflectionType::allowsNull — 檢查是否允許 null
此函式沒有參數。
範例 #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)