ReflectionUnionType::getTypes

(PHP 8)

ReflectionUnionType::getTypesReturns the types included in the union type

Descripción

publicReflectionUnionType::getTypes(): array

Returns the reflections of types included in the union type.

Parámetros

Esta función no tiene parámetros.

Valores devueltos

An array of ReflectionType objects.

Ejemplos

Ejemplo #1 ReflectionUnionType::getTypes() example

<?php
function someFunction(int|float $number) {}

$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParam = $reflectionFunc->getParameters()[0];

var_dump($reflectionParam->getType()->getTypes());

El resultado del ejemplo sería algo similar a:

array(2) { [0] => class ReflectionNamedType#4(0) { } [1] => class ReflectionNamedType#5(0) { } }

Ver también

To Top