php8.5
Home/ Manual/ reflection / reflectionenum/ ReflectionEnum::hasCase

ReflectionEnum::hasCase

PHP function Edit on GitHub ✎

(PHP 8 >= 8.1.0)

Checks for a case on an Enum

Description

ReflectionEnum::hasCase(string $name): bool

Determines if a given case is defined on an Enum.

Parameters

name

The case to check for.

Return Values

true if the case is defined, false if not.

Examples

ReflectionEnum::hasCase example

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

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

var_dump($rEnum->hasCase('Hearts'));
var_dump($rEnum->hasCase('Horseshoes'));
?>

The above example will output:

output
bool(true)
bool(false)

See Also

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