I was wondering why the getKey function didn't properly return flags when I realized it apparently expects every single value to be represented in the range of bits in the mask (in addition to a "zero" dummy value at the end of it all).
For instance, a bitmask that defines values of 1, 4, 128, you won't ever get a proper array for anything but the 1 value.
I propose that since each value is supposed to represent a single-bit mask in the bitmask anyways, the function could be thus:
public function getKey()
{
$value = $this->value;
$f = array_filter(static::toArray(), function ($key) use (&$value) {
return $value & $key;
});
return array_keys($f);
}
I was wondering why the
getKeyfunction didn't properly return flags when I realized it apparently expects every single value to be represented in the range of bits in the mask (in addition to a "zero" dummy value at the end of it all).For instance, a bitmask that defines values of 1, 4, 128, you won't ever get a proper array for anything but the 1 value.
I propose that since each value is supposed to represent a single-bit mask in the bitmask anyways, the function could be thus: