[php-src] PR #22043: Add `BackedEnum::values()` method to retrieve backing values as an array

From: Date: Thu, 14 May 2026 23:49:52 +0000
Subject: [php-src] PR #22043: Add `BackedEnum::values()` method to retrieve backing values as an array
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-36126@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/22043 Author: duiliofanton # Proposal Add a new static method to BackedEnum: ```php BackedEnum::values(): array ``` The method returns all backing values from the enum cases. Example: ```php enum Status: string { case ACTIVE = 'active'; case INACTIVE = 'inactive'; } Status::values(); ``` Result: ```php ['active', 'inactive'] ``` Integer backed enum: ```php enum HttpStatus: int { case OK = 200; case NOT_FOUND = 404; } HttpStatus::values(); ``` Result: ```php [200, 404] ``` This provides a simple and direct way to retrieve enum backing values without requiring additional array transformations. Currently this typically requires: ```php array_column(Status::cases(), 'value'); ``` The proposed API makes the intent explicit and easier to read: ```php Status::values(); ``` The method would only exist on BackedEnum, since UnitEnum cases do not contain backing values. --- ## Rationale The proposal intentionally keeps the scope minimal. cases() already provides access to enum case objects and names when needed. The goal of values() is specifically to provide direct access to backing values for BackedEnum, which is currently a very common operation that requires additional array transformations. This proposal does not introduce a generic collection-style API for enums. Methods such as map(), filter(), keys(), or similar helpers are outside the scope of this RFC. values() addresses a single focused use case: ```php Status::values(); ``` which is currently commonly written as: ```php array_column(Status::cases(), 'value'); ``` The intention is to provide a clearer and more direct API for retrieving enum backing values only.

« previous php.git-pulls (#36126) next »