PHP 8.5.0 Beta 3 available for testing

ReflectionIntersectionType::getTypes

(PHP 8 >= 8.1.0)

ReflectionIntersectionType::getTypes — čŋ”回包åĢ在äē¤é›†įąģåž‹ä¸­įš„įąģ型

č¯´æ˜Ž

public ReflectionIntersectionType::getTypes(): array

čŋ”回包åĢ在äē¤é›†įąģåž‹ä¸­įš„įąģåž‹įš„åå°„ã€‚

参数

æ­¤å‡Ŋæ•°æ˛Ąæœ‰å‚æ•°ã€‚

čŋ”回å€ŧ

包åĢ 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 note

up
2
baptiste at pillot dot fr Âļ
2 years ago
php 8.2: ReflectionIntersectionType::getTypes returns an array of ReflectionNamedType. For now, PHP's DNF implementation does not allow union types nested into intersection types.
To Top