PHPackages                             framjet/enum-bitmask - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. framjet/enum-bitmask

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

framjet/enum-bitmask
====================

A small library that provides functionality to PHP 8.1 enums to act as BitMask flags

1.0.0(4y ago)58585MITPHPPHP ~8.1.0

Since Dec 28Pushed 4y ago3 watchersCompare

[ Source](https://github.com/framjet/php-enum-bitmask)[ Packagist](https://packagist.org/packages/framjet/enum-bitmask)[ Docs](https://github.com/framjet/php-enum-bitmask)[ RSS](/packages/framjet-enum-bitmask/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

PHP Enum BitMask
================

[](#php-enum-bitmask)

[![Latest Stable Version](https://camo.githubusercontent.com/2f635e82580b84c617f4ec4f0527fa51f0388da64bf3e2181fd8dd0463686c5d/687474703a2f2f706f7365722e707567782e6f72672f6672616d6a65742f656e756d2d6269746d61736b2f76)](https://packagist.org/packages/framjet/enum-bitmask)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/61b12920143729c4ad50ba8a1cb052e7a252b27603f870cd96aee1bb7ab7020b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6672616d6a65742f7068702d656e756d2d6269746d61736b2f436f6e74696e756f7573253230496e746567726174696f6e)](https://github.com/framjet/php-enum-bitmask/actions)[![Total Downloads](https://camo.githubusercontent.com/2c50b41c43e569ada8d4725cf0f0c43d8948e44f63504743490b8c10bfd1d193/687474703a2f2f706f7365722e707567782e6f72672f6672616d6a65742f656e756d2d6269746d61736b2f646f776e6c6f616473)](https://packagist.org/packages/framjet/enum-bitmask)[![Dependents](https://camo.githubusercontent.com/409986d0ddc31512d1b6637ce86bd250de489ea90b04657fa061336d52f2dbcb/687474703a2f2f706f7365722e707567782e6f72672f6672616d6a65742f656e756d2d6269746d61736b2f646570656e64656e7473)](https://packagist.org/packages/framjet/enum-bitmask/dependents?order_by=downloads)[![PHP Version Require](https://camo.githubusercontent.com/81727a5d0d04d5f6766433d2ddee8ffdaadc9a5933d659a2f483daff8269c41e/687474703a2f2f706f7365722e707567782e6f72672f6672616d6a65742f656e756d2d6269746d61736b2f726571756972652f706870)](https://packagist.org/packages/framjet/enum-bitmask)[![Mutation testing badge](https://camo.githubusercontent.com/13923c7060cbda9f67c99efc0758e674bd2e836b0ab123ba9d4c500f329828a0/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466672616d6a65742532467068702d656e756d2d6269746d61736b2532466d61696e)](https://dashboard.stryker-mutator.io/reports/github.com/framjet/php-enum-bitmask/main)[![Type Coverage](https://camo.githubusercontent.com/1571e178a82d83841c12a2f776d83f5af8126515d6d08ae16cca8c4c0134448c/68747470733a2f2f73686570686572642e6465762f6769746875622f6672616d6a65742f7068702d656e756d2d6269746d61736b2f636f7665726167652e737667)](https://shepherd.dev/github/framjet/php-enum-bitmask)

[![Email](https://camo.githubusercontent.com/112823eab3950f8ca6b8aae47d9bbd21f6d0ba27045d8e5ebe2142007ba79be3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f656d61696c2d7465616d406672616d6a65742e6465762d626c75652e737667)](mailto:team@framjet.dev)

A small library that provides functionality to PHP 8.1 enums to act as BitMask flags.

Why?
----

[](#why)

Sometimes you need some flags on the objects, to represent some features, most often its used simple property with the type of `bool` but then you start making several properties and then your object size (Serialized/JSON) starts growing quite a lot.

The most efficient storage option for flags was always bitmask value. It provides up to 32 unique flags inside a single `int32` value.

Another big benefit is the ability to make `AND`, `OR`, `NOT` operations in one call instead of doing many if expressions to check all those property values.

Install
-------

[](#install)

Via [Composer](https://getcomposer.org/)

```
$ composer require framjet/enum-bitmask
```

Usage
-----

[](#usage)

The library provides a trait [`BitmaskFunctionality`](src/BitmaskFunctionality.php) which is needed to include inside int backed enum.

Here is a tiny example of using `Enum` to provide flags using space-efficient bitmask int value:

```
