PHPackages                             axetools/bitflagtrait - 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. axetools/bitflagtrait

ActiveLibrary

axetools/bitflagtrait
=====================

A PHP trait to enable bitwise comparison of flags

v2.0.1(1y ago)04.0k↓100%1MITPHPPHP ^7.1 || ^8.0

Since Jul 17Pushed 1y agoCompare

[ Source](https://github.com/AxeTools/BitFlagTrait)[ Packagist](https://packagist.org/packages/axetools/bitflagtrait)[ RSS](/packages/axetools-bitflagtrait/feed)WikiDiscussions 2.x Synced 1mo ago

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

AxeTools/BitFlagTrait
=====================

[](#axetoolsbitflagtrait)

 **This is a php class trait that will provide methods for performing simple bitwise operations.**

 [![Source Code](https://camo.githubusercontent.com/0ff709d48051af06d7c1036a3a1dc772feca53b896e265d099c50b20eaee9715/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d417865546f6f6c732f426974466c616754726169742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/AxeTools/BitFlagTrait) [![PHP Programming Language](https://camo.githubusercontent.com/58edbdcbf3ce3c0c6e644f7299ccfc7c0c4b1a41e540ef5e38d09583d86ceb2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f417865546f6f6c732f426974466c616754726169742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d253233383839324246)](https://php.net) [![Read License]()](https://github.com/AxeTools/BitFlagTrait/blob/2.x/LICENSE) [![Build Status]()](https://github.com/AxeTools/BitFlagTrait/actions/workflows/php.yml)

This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[Bitwise operators](https://www.php.net/manual/en/language.operators.bitwise.php) allow for manipulation and examination of specific bits within an integer.

The `BitFlagTrait` gives simple methods for setting, getting and toggling the status of bits withing a reference integer.

This can be used for storage of the state of multiple flags or utilizing flags for class settings

Installation
------------

[](#installation)

The preferred method of installation is via [Composer](http://getcomposer.org/). Run the following command to install the package and add it as a requirement to your project's `composer.json`:

```
composer require axetools/bitflagtrait
```

Usage
-----

[](#usage)

The BitFlagTrait can be used with any class and will expose several protected methods that can be utilized to perform bitwise checks to a reference integer.

### Example:

[](#example)

```
