Thank you! Seems like Enum covers this case. вс, 1 авг. 2021 г., 21:58 Rowan Tommins <rowan.coll...@gmail.com>:
> On 01/08/2021 16:59, Serhii Smirnov wrote: > > class Features > > { > > const FEATURE_FLAG_WITH_SOME_LONG_NAME = > > 'feature_flag_with_some_long_name'; > > const FEATURE_SOME_ANOTHER_COOL_FEATURE = > > 'feature_some_another_cool_feature'; > > } > > > That looks like it falls into my first category: the actual value of the > constant doesn't matter, you just need to be able to compare against it > later. > > That makes it a perfect use case for PHP 8.1's new "enum" type, where > you'll be able to declare this: > > enum Feature > { > case FEATURE_FLAG_WITH_SOME_LONG_NAME; > case FEATURE_SOME_ANOTHER_COOL_FEATURE; > } > > You can then even define the "isEnabled" function so that it only > accepts Feature values, not strings (i.e. "public function > isEnabled(Feature $feature): bool { ... }" instead of "public function > isEnabled(string $feature): bool { ... }"). > > If you're not familiar with the new enums, the best documentation at the > moment is probably the RFC which proposed them: > https://wiki.php.net/rfc/enumerations > > I'm really looking forward to using them :) > > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >