-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
Right now the order and position within the enum determine the result. This introduces some problems.
Bitmasks are often used to check permissions etc, therefore the minor risks should be taken more seriously I believe.
- Very sensitive to potential dangerous bugs when someone is not aware of the implications and makes a change to the enum. Or "small" codestyle fixes done to order enum cases alphabetically may have grave consequences when gone unnoticed.
- I cannot migrate pre-existing bitmasks to enums, since some values were removed over time. I might have constants like this:
public const MASK_PERMISSION_1 = 1 << 1;
public const MASK_PERMISSION_2 = 1 << 3;
public const MASK_PERMISSION_3 = 1 << 4;
Right now I would have to add placeholders to use this bundle without changing the bitmask itself.
enum Permissions {
case Permission1;
case Missing1;
case Permission2;
case Permission3;
}
Obviously, this is not what I need, even more so when more values are missing.
Proposed solution:
Add support for int backed enums. Optionally add an argument to the EnumBitmask constructor.
For example:
enum Permissions: int {
case Permission1 = 1 << 1;
case Permission2 = 1 << 3;
case Permission3 = 1 << 4;
}
$bitmask = new EnumBitmask(enum: Permissions::class, mask: 0, maskValues: true);
For now I'll just implement my own EnumBitmask because I cannot wait for this change.
If you agree to the solution I don't mind to create a pull request for it.
yaroslavche
Metadata
Metadata
Assignees
Labels
No labels