You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting in `v2.1.0`, passing `float` values as masks or flags is deprecated.
25
+
26
+
- Current `v2.x` behavior: floats are still accepted for backward compatibility, but trigger a deprecation warning.
27
+
-`v3.0.0` behavior: masks and flags will be `int`-only.
28
+
-`v3.0.0` behavior: `Bits::BIT_64` will be removed.
29
+
30
+
### BIT_64 Notice
31
+
`Bits::BIT_64` is being removed because PHP numbers for bitwise flags are signed. The 64th bit is the sign bit, so it cannot be used reliably as a normal flag.
32
+
33
+
Using integer-compatible bits (`BIT_1` through `BIT_63`) prevents these issues and is the supported path for `v3.0.0`.
34
+
35
+
To prepare for `v3.0.0`, cast incoming values before using the API:
36
+
37
+
```php
38
+
$flags->setMask((int) $maskFromLegacySource);
39
+
$flags->addFlag((int) $incomingFlag);
40
+
```
41
+
42
+
See [UPGRADE-v3.md](UPGRADE-v3.md) for migration details.
43
+
18
44
## Methods
19
45
The following methods can be used:
20
46
@@ -25,6 +51,14 @@ This can be passed as first argument in the constructor.
25
51
##### getMask(): int
26
52
Retrieve the current mask.
27
53
54
+
When using `BinaryEnumFlags`, `getMask()` returns a `Mask` object instead.
55
+
Use `getMaskValue(): int` on enum-based flags if you need the numeric mask.
56
+
57
+
##### getMaskValue(): int
58
+
_Since: v2.1.0_\
59
+
Returns the numeric mask value for storage/interoperability.
60
+
This method is only available on enum-backed flags (`BinaryEnumFlags`).
61
+
28
62
##### setOnModifyCallback(callable $onModify)
29
63
Set a callback function which is called when the mask changes.
30
64
This can be passed as second argument in the constructor.
@@ -47,7 +81,7 @@ When you want to match any of the given flags set `$checkAll` to `false`.
47
81
48
82
##### checkAnyFlag(int $mask): bool
49
83
_Since: v1.0.1_\
50
-
For you convenient I've added an alias to checkFlag with `$checkAll` set to `false`.
84
+
For your convenience I've added an alias to checkFlag with `$checkAll` set to `false`.
51
85
52
86
##### count(): int
53
87
_Since: v1.2.0_\
@@ -77,7 +111,7 @@ You can treat a BinaryFlags object as an iterable, where each iteration will ret
- Enum-backed flags now return a `Mask` object from `getMask()`.
9
+
- New `getMaskValue(): int` method for enum-backed flags to persist/interoperate with integer masks.
10
+
- Deprecation warnings for passing `float` values as masks/flags.
11
+
- README migration notice for the upcoming `v3.0.0` integer-only API.
12
+
-`UPGRADE-v3.md` with migration instructions.
13
+
- New primary numeric trait: `Traits\InteractsWithNumericFlags`.
14
+
-`Traits\BinaryFlags` is now deprecated and kept for backward compatibility.
15
+
16
+
## Deprecated
17
+
- Passing `float` to BinaryFlags mask/flag methods is deprecated in `v2.1.0`.
18
+
- Float support will be removed in `v3.0.0`.
19
+
-`Bits::BIT_64` will be removed in `v3.0.0`.
20
+
21
+
## BIT_64 Notice
22
+
`Bits::BIT_64` is being removed because PHP numbers for bitwise flags are signed. The 64th bit is the sign bit, so it cannot be used reliably as a normal flag.
23
+
24
+
Using integer-compatible bits avoids these issues.
25
+
26
+
## Migration Recommendation
27
+
Cast external/legacy mask and flag values to `int` before calling BinaryFlags methods.
`v3.0.0` removes support for `float` values in masks and flags.
5
+
`v3.0.0` also removes `Bits::BIT_64`.
6
+
7
+
## What Changed
8
+
-`v2.x`: `int|float` accepted in mask/flag methods.
9
+
-`v3.0.0`: only `int` is accepted.
10
+
-`v2.x`: `Bits::BIT_64` exists but is not reliable in real bitwise usage.
11
+
-`v3.0.0`: `Bits::BIT_64` is removed. Use `BIT_1` through `BIT_63`.
12
+
13
+
## How to Migrate
14
+
1. Find every call that passes mask/flag values into BinaryFlags methods.
15
+
2. Ensure values are cast to `int` before passing them.
16
+
3. Ensure database or external sources provide integer-compatible values.
17
+
18
+
## Example
19
+
Before:
20
+
```php
21
+
$flags->setMask($legacyValue);
22
+
$flags->addFlag($legacyFlag);
23
+
```
24
+
25
+
After:
26
+
```php
27
+
$flags->setMask((int) $legacyValue);
28
+
$flags->addFlag((int) $legacyFlag);
29
+
```
30
+
31
+
## v2.1+ Deprecation Signal
32
+
Starting in `v2.1.0`, float inputs trigger deprecation warnings to help detect call sites before moving to `v3.0.0`.
33
+
34
+
## Why BIT_64 Is Being Removed
35
+
`BIT_64` is being removed because PHP numbers for bitwise flags are signed. The 64th bit is the sign bit, so it cannot be used reliably as a normal flag.
36
+
37
+
Staying with integer-compatible bits prevents those runtime issues.
0 commit comments