PHP 8.1.28 Released!

ReflectionEnum::getBackingType

(PHP 8 >= 8.1.0)

ReflectionEnum::getBackingTypeGets the backing type of an Enum, if any

Açıklama

public ReflectionEnum::getBackingType(): ?ReflectionNamedType

If the enumeration is a Backed Enum, this method will return an instance of ReflectionType for the backing type of the Enum. If it is not a Backed Enum, it will return null.

Bağımsız Değişkenler

Bu işlevin bağımsız değişkeni yoktur.

Dönen Değerler

An instance of ReflectionNamedType, or null if the Enum has no backing type.

Sürüm Bilgisi

Sürüm: Açıklama
8.2.0 The return type is now declared as ?ReflectionNamedType. Previously, ?ReflectionType was declared.

Örnekler

Örnek 1 ReflectionEnum::getBackingType() example

<?php
enum Suit: string
{
case
Hearts = 'H';
case
Diamonds = 'D';
case
Clubs = 'C';
case
Spades = 'S';
}

$rEnum = new ReflectionEnum(Suit::class);

$rBackingType = $rEnum->getBackingType();

var_dump((string)$rBackingType);
?>

Yukarıdaki örneğin çıktısı:

string(6) "string"

Ayrıca Bakınız

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top