I have declared some values in an enum class as below,
enum EmployeeGroup: int
{
case ADMINISTRATOR = 1;
case GROUP_DEFAULT = 2;
case DIRECTOR = 3;
case DUH = 4;
case TEAM_LEAD = 5;
case SUPER_USER = 6;
case HR = 7;
case PROJECT_MANAGER = 8;
case ENGINEER = 9;
case SENIOR_ENGINEER = 10;
case FUNC_LEADS = 11;
case SUPPORT_MEMBERS = 12;
}
I used them in another class s below. This static variable needs an array of values as its input.
class TeamMenu extends Menu
{
/**
* Permitted user groups to view menu
*
* @var array
*/
static $permitted = [
EmployeeGroup::DUH->value,
EmployeeGroup::HR->value,
EmployeeGroup::PROJECT_MANAGER->value,
EmployeeGroup::ENGINEER->value,
EmployeeGroup::SENIOR_ENGINEER->value,
];
}
So, what I need is to get the integer values from enum class and include them in $permitted variable. But, when I run this code, I get an error saying,
Constant expression contains invalid operations
What is the reason for this error? (My php version is 8.1)