ReflectionEnum::getBackingType
(PHP 8 >= 8.1.0)
ReflectionEnum::getBackingType — Gets the backing type of an Enum, if any
Description
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.
Parameters
This function has no parameters.
Examples
Example #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);
?>
The above example will output: