[php-src] Issue #8344: Attribute parameters cannot contain BackedEnum values
| From: | michnovka | Date: | Mon, 11 Apr 2022 19:10:15 +0000 |
| Subject: | [php-src] Issue #8344: Attribute parameters cannot contain BackedEnum values | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240845@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8344
Comment Author: michnovka
@damianwadley I tried to make the example as minimal as possible. The reason why not use the enum
directly is that I need it as an array key for my implementation
```php
<?php
enum Status: string
{
case DRAFT = 'draft';
case PUBLISHED = 'published';
case ARCHIVED = 'archived';
}
#[Attribute]
class ListensTo
{
public array $events;
public function __construct(array $events)
{
$this->events = $events;
}
}
#[ListensTo([Status::DRAFT->value => true])]
class TestClass {}
```
This Attribute is from a 3rd party library and I cannot change it. The key values correspond to
values of enum cases I have specified elsewhere in the project. So now I have to have "magic
strings" like
```php
#[ListensTo(['DRAFT' => true])]
```
And when I change
Status::DRAFT, I need to change it on more places.