> For the complete documentation index, see [llms.txt](https://docs.opensoutheners.com/oss/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opensoutheners.com/oss/extended-php/enums-helpers.md).

# Enums helpers

List of functions that works for PHP enums.

## is\_enum

Check if object or class is a PHP enum.

```php
enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\is_enum(MyEnum::class); // true
```

## enum\_is\_backed

Check if object or class is a backed PHP enum.

```php
enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\enum_is_backed(MyEnum::class); // false
```

## has\_case

Check if object or class is a PHP enum that has the specified case.

```php
enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\has_case(MyEnum::class, 'First'); // true
```

## get\_enum\_class

Get class string from enum object.

```php
enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\get_enum_class(MyEnum::First); // 'MyEnum'
```

## enum\_to\_array

Converts PHP enum object or class into an array. In case of a backed enum it will add its values.

```php
enum MyEnum
{
    case First;

    case Second;

    case Third;
}

\OpenSoutheners\ExtendedPhp\Enums\enum_to_array(MyEnum::class);
// ['First', 'Second', 'Third']
```

## enum\_values

Gets array of values from PHP backed enum.

```php
enum MyBackedEnum: string
{
    case First = 'one';

    case Second = 'two';

    case Third = 'three';
}

\OpenSoutheners\ExtendedPhp\Enums\enum_values(MyBackedEnum::class);
// ['one', 'two', 'three']
```

## GetsAttributes

{% hint style="info" %}
This is not a function but still serves as a utility. **Make sure you only use this with backed enums**.
{% endhint %}

This trait will add some functions to the PHP enums so they can be converted to arrays to be used in multiple contexts (like HTML selects, etc).

### Description

This is a PHP attribute to be used in those enum cases to be used along with `GetsAttribute` trait:

```php
use OpenSoutheners\ExtendedPhp\Enums\Description;
use OpenSoutheners\ExtendedPhp\Enums\GetsAttributes;

enum MyBackedEnum: string
{
    use GetsAttributes;

    #[Description('First point')]
    case First = 'one';
    #[Description('Second point')]
    case Second = 'two';
    #[Description('Third point')]
    case Third = 'three';
}
```

More details of their usage below.

### asSelectArray

The only public method available on this trait which will **get all described cases** of your enum.

Now imagine the case having the enum shown before:

```php
MyBackedEnum::asSelectArray();
// ['one' => 'First point', 'two' => 'Second point', 'three' => 'Third point']
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.opensoutheners.com/oss/extended-php/enums-helpers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
