PHP Conference Japan 2024

ReflectionIntersectionType::getTypes

(PHP 8 >= 8.1.0)

ReflectionIntersectionType::getTypes傳回交集類型中包含的類型

說明

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

參見

新增註解

使用者貢獻的註解 1 則註解

baptiste at pillot dot fr
1 年前
php 8.2: ReflectionIntersectionType::getTypes 會回傳一個 ReflectionNamedType 的陣列。目前,PHP 的 DNF 實作不允許在交集類型中嵌套聯集類型。
To Top