PHP 8.1.2 Released!

ReflectionEnum::isBacked

(PHP 8 >= 8.1.0)

ReflectionEnum::isBackedDetermines if an Enum is a Backed Enum

Description

public ReflectionEnum::isBacked(): bool

A Backed Enum is one that has a native backing scalar equivalent, either a string or an int. Not all Enums are backed.

Liste de param├Ętres

Cette fonction ne contient aucun param├Ętre.

Valeurs de retour

true if the Enum has a backing scalar, false if not.

Exemples

Exemple #1 ReflectionEnum::isBacked() example

<?php
enum Suit
{
    case 
Hearts;
    case 
Diamonds;
    case 
Clubs;
    case 
Spades;
}

enum BackedSuitstring
{
    case 
Hearts 'H';
    case 
Diamonds 'D';
    case 
Clubs 'C';
    case 
Spades 'S';
}

var_dump((new ReflectionEnum(Suit::class))->isBacked());
var_dump((new ReflectionEnum(BackedSuit::class))->isBacked());
?>

L'exemple ci-dessus va afficher :

bool(false)
bool(true)

Voir aussi

add a note add a note

User Contributed Notes

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