PHP.mk документација

ReflectionUnionType::getTypes

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

reflectionuniontype.gettypes.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека reflectionuniontype.gettypes.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ReflectionUnionType::getTypes

Референца за `reflectionuniontype.gettypes.php` со подобрена типографија и навигација.

reflectionuniontype.gettypes.php

ReflectionUnionType::getTypes

(PHP 8)

ReflectionUnionType::getTypes(PHP 8)

= NULL

public ReflectionUnionType::getTypes(): array

Враќа типови вклучени во унијата на типови

Параметри

Оваа функција нема параметри.

Вратени вредности

(и сè уште не е затворена со ReflectionType objects.

Примери

Пример #1 Враќа рефлексии на типови вклучени во унијата на типови. example

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

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

Види Исто така

Белешки од корисници 2 забелешки

Нова инстанца на атрибутот.
пред 2 години
Sorting :

Contrary to what one might expect, the returned array of ReflectionType objects will not be sorted in the same order than the types declared into the source code.

- Classes, interfaces, traits, iterable (replaced by Traversable), ReflectionIntersectionType objects, parent and self: these types will be returned first, in the order in which they were declared.
- static and all built-in types (iterable replaced by array) will come next. They will always be returned in this order: static, callable, array, string, int, float, bool (or false or true), null.

Notice that when used into an union type, iterable is an alias for Traversable|array. ReflectionUnionType::getTypes will return these both ReflectionNamedType objects, instead of a single one named 'iterable'.

Example :
<?php
class PC {}
class C extends PC {
    function f(): null|bool|float|int|parent|PC|string|iterable|(ReflectionClass&ReflectionProperty)|callable|static|self|C {}
}
echo join(', ', array_map(
    function($t) { return ($t instanceof ReflectionIntersectionType) ? '<intersection>' : $t->getName(); },
    (new ReflectionMethod('C', 'f'))->getReturnType()->getTypes()
)) . "\n";
?>

Will display :
parent, PC, Traversable, <intersection>, self, C, static, callable, array, string, int, float, bool, null

Try it: https://onlinephp.io/c/777c6
Нова инстанца на атрибутот.
пред 2 години
ReflectionUnionType::getTypes can return an array of ReflectionNamedType and/or ReflectionIntersectionType objects only.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.