1.2.1326. Use Enum Case In Constant Expression¶
Enum cases are constants, and may be used in constant definitions, as value. This is valid both with the case itself, or with their value, for the backed enum version.
<?php
enum A {
case A;
}
enum B : string {
case B = 'b';
}
class C {
const C1 = A::A;
const C2 = B::B->value;
}
?>
1.2.1326.1. Specs¶
Short name |
Php/UseEnumCaseInConstantExpression |
Rulesets |
All, Appinfo, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80, CompatibilityPHP81 |
Exakat since |
2.5.3 |
PHP Version |
With PHP 8.2 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Available in |