PHP 8.0.0 以降では、以下のコードは
union の一部であった場合も含めて、配列型を宣言しているかどうかを報告します。
<?php
function declaresArray(ReflectionParameter $reflectionParameter): bool
{
$reflectionType = $reflectionParameter->getType();
if (!$reflectionType) return false;
$types = $reflectionType instanceof ReflectionUnionType
? $reflectionType->getTypes()
: [$reflectionType];
return in_array('array', array_map(fn(ReflectionNamedType $t) => $t->getName(), $types));
}
?>