[php-src] Issue #9208: Enum case as Array key?

From: Date: Sun, 31 Jul 2022 11:18:44 +0000
Subject: [php-src] Issue #9208: Enum case as Array key?
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242088@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9208 Author: geraldofebrian ### Description Before enum exist, i used constant to define the array key. Now i want to use enum. But i got error when i declare the enum as array key. so i do the workaround like this: ``` if (!function_exists('_api')) { /** * use enum as Array Key. * * @param array $values * @param \App\Enums\Api\ResponseKey $key * @param mixed $data * @return array */ function _api(?array &$values, ResponseKey $key, $data) { if (! is_array($values)) $values = []; $values[$key->value] = $data; return $values; } } ``` Then call it like _api($data, ResponseKey::message, "success"); Can this *workaround* can be implemented as feature for future PHP?

« previous php.bugs (#242088) next »