Download the PHP package marc-mabe/enum-cl without Composer
On this page you can find all versions of the php package marc-mabe/enum-cl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marc-mabe/enum-cl
More information about marc-mabe/enum-cl
Files in marc-mabe/enum-cl
Package enum-cl
Short Description Compatibility layer for emulating enumerations in PHP < 8.1 and native enumerations in PHP >= 8.1
License BSD-3-Clause
Homepage https://github.com/marc-mabe/php-enum-cl
Informations about the package enum-cl
Compatibility layer for emulating enumerations in PHP \< 8.1 but native enumerations in PHP >= 8.1
How-to create
Vendor\MyEnum.php
Vendor\MyEnum-emulated.php
Vendor\MyEnum-native.php
Enum type | native | emulated |
---|---|---|
Unit enum | enum ENUMNAME { |
final class ENUMNAME extends \Mabe\Enum\Cl\EmulatedUnitEnum { |
Integer backed enum | enum ENUMNAME:int { |
final class ENUMNAME extends \Mabe\Enum\Cl\EmulatedIntEnum { |
String backed enum | enum ENUMNAME:string { |
final class ENUMNAME extends \Mabe\Enum\Cl\EmulatedStringEnum { |
For IDE and static code analyzers I recommend adding the following docblock:
How-to use
The following will work the same on PHP<8.1 (using emulated enums) and on PHP>=8.1 (using native enums):
Warning: The following will not behave the same on all PHP versions:
Additional Notes
PHPStan
By default PHPStan will complain about unused constants as it can't automatically detect the special use via reflection in this case.
To avoid this you need to add the following to your phpstan.neon[.dist]
:
For more information please read https://phpstan.org/developing-extensions/always-used-class-constants
Included Polyfills
This library includes the following polyfills (if not already present):
get_debug_type
All versions of enum-cl with dependencies
ext-reflection Version *
composer-runtime-api Version ^2.0