Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<ReflectionEnum::getCasesReflectionEnum::isBacked>
^ReflectionEnumLast updated: Mon, 26 Oct 2026

ReflectionEnum::hasCase

(PHP 8 >= 8.1.0)

ReflectionEnum::hasCase — Checks for a case on an Enum

Description

public function 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

Example #1 ReflectionEnum::hasCase() example

<?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:

bool(true)
bool(false)

See Also


<ReflectionEnum::getCasesReflectionEnum::isBacked>
^ReflectionEnumLast updated: Mon, 26 Oct 2026