ReflectionEnumBackedCase::getBackingValue

(PHP 8 >= 8.1.0)

ReflectionEnumBackedCase::getBackingValueGets the scalar value backing this Enum case

Description

public ReflectionEnumBackedCase::getBackingValue(): int|string

Gets the scalar value backing this Enum case.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

The scalar equivalent of this enum case.

Exemples

Exemple #1 ReflectionEnum::getBackingValue() example

<?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());
?>

L'exemple ci-dessus va afficher :

string(1) "S"

Voir aussi

add a note add a note

User Contributed Notes

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