ReflectionIntersectionType::getTypes

(PHP 8 >= 8.1.0)

ReflectionIntersectionType::getTypes — äș€ć·źćž‹ă«ć«ăŸă‚ŒăŠă„ă‚‹ćž‹ă‚’èż”ă™

èȘŹæ˜Ž

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

ć‚è€ƒ

add a note

User Contributed Notes 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.