php 8.2: ReflectionIntersectionType::getTypes 會回傳一個 ReflectionNamedType 的陣列。目前,PHP 的 DNF 實作不允許在交集類型中嵌套聯集類型。
(PHP 8 >= 8.1.0)
ReflectionIntersectionType::getTypes — 傳回交集類型中包含的類型
此函式沒有參數。
一個 ReflectionType 物件的陣列。
範例 #1 ReflectionIntersectionType::getTypes() 範例
<?php
function someFunction(Iterator&Countable $value) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParam = $reflectionFunc->getParameters()[0];
var_dump($reflectionParam->getType()->getTypes());
?>
上述範例將輸出類似以下的內容
array(2) { [0] => class ReflectionNamedType#4(0) { } [1] => class ReflectionNamedType#5(0) { } }
php 8.2: ReflectionIntersectionType::getTypes 會回傳一個 ReflectionNamedType 的陣列。目前,PHP 的 DNF 實作不允許在交集類型中嵌套聯集類型。