php8.5
Home/ Manual/ reflection / reflectionenumbackedcase/ ReflectionEnumBackedCase::getBackingValue

ReflectionEnumBackedCase::getBackingValue

PHP function Edit on GitHub ✎

(PHP 8 >= 8.1.0)

Gets the scalar value backing this Enum case

Description

ReflectionEnumBackedCase::getBackingValue(): int|string

Gets the scalar value backing this Enum case.

Parameters Parameters

Return Values

The scalar equivalent of this enum case.

Examples

ReflectionEnum::getBackingValue example

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

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

$rCase = $rEnum->getCase('Spades');

var_dump($rCase->getBackingValue());
?>

The above example will output:

output
string(1) "S"

See Also

Source: reference/reflection/reflectionenumbackedcase/getbackingvalue.xml · from the official PHP manual (php/doc-en)