PHPackages                             wilensky/bitmask-trait - 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. wilensky/bitmask-trait

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

wilensky/bitmask-trait
======================

Universal PHP7 trait that provides easy bitmask management and integration

v1.1(9y ago)51.7k↓50%MITPHPPHP &gt;=7.0.1

Since Jan 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/wilensky/BitmaskTrait)[ Packagist](https://packagist.org/packages/wilensky/bitmask-trait)[ Docs](https://github.com/wilensky/BitmaskTrait)[ RSS](/packages/wilensky-bitmask-trait/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

BitmaskTrait [![Build Status](https://camo.githubusercontent.com/e8e8b14d5e45745dac69f46571a4283422c961e714bcde190d7d6129307d90b0/68747470733a2f2f7472617669732d63692e6f72672f77696c656e736b792f4269746d61736b54726169742e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/wilensky/BitmaskTrait)
==========================================================================================================================================================================================================================================================================================================

[](#bitmasktrait-)

PHP7 bitmask modem trait provides seamless integration of bitmasks in your application.

Bitmasks are useful in case when multiple states should be assigned to a single entity or/and exist simultaneously. With help of this trait you can easily pack up to 32/64 states in a single integer like no one else.

Generic example
---------------

[](#generic-example)

Lets take regular invoice to demonstrate the essence.

Assuming invoice has several states:

*State*SentOpenedClosedFailedArchived*Bit*01234And related payment can have more than one state:

*State*In progressSuccessfulAuth. failedCanceledFailedRefusedRefunded*Bit*0123456Looks like to organize states for both invoice and payment we would need **12 fields**, but not with the bitmask.

What we can do is easily **pack all** 12 states **in a single** well known **integer**. Assumed state map can be the following:

*State*SentOpenedClosedFailedArchivedIn progressSuccessfulAuth. failedCanceledFailedRefusedRefunded*Bit*01234567891011It can look the following way over time:

BitmaskSentOpenedClosedFailedArchivedIn progressSuccessfullAuth. failedCancelledFailedRefusedRefunded*Bit*01234567891011Invoice sent to customer3++Invoice payment initiated35+++Payment successfull69+++Payment refunded2117+++++Payment auth. failed137+++Basic usage
-----------

[](#basic-usage)

```
