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

ActiveLibrary

gksh/bitmask
============

A bitmask value object for PHP

v1.0.0(4mo ago)7651MITPHPPHP ^8.2CI failing

Since May 3Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/dotgksh/bitmask)[ Packagist](https://packagist.org/packages/gksh/bitmask)[ GitHub Sponsors](https://github.com/karkowg)[ RSS](/packages/gksh-bitmask/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (1)

 [![Bitmask banner](https://camo.githubusercontent.com/a44986d26a9ef5a6d3900fba8ce8f6b58c6515f16e6106c30066978d41e68a70/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f676b73682532466269746d61736b2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d676b73682532466269746d61736b267061747465726e3d776967676c65267374796c653d7374796c655f31266465736372697074696f6e3d412b6269746d61736b2b76616c75652b6f626a6563742b666f722b504850266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d323030707826696d616765733d666c6167267769647468733d31303026686569676874733d313030)](https://camo.githubusercontent.com/a44986d26a9ef5a6d3900fba8ce8f6b58c6515f16e6106c30066978d41e68a70/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f676b73682532466269746d61736b2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d676b73682532466269746d61736b267061747465726e3d776967676c65267374796c653d7374796c655f31266465736372697074696f6e3d412b6269746d61736b2b76616c75652b6f626a6563742b666f722b504850266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d323030707826696d616765733d666c6167267769647468733d31303026686569676874733d313030)

gksh/bitmask
============

[](#gkshbitmask)

A simple way to use bitmask and bitwise operations in PHP.

[![Latest Version on Packagist](https://camo.githubusercontent.com/2c1d7e2bb92e01bbc31ea5eb8306f9a56867af3520a2c62d62f0a7f6e55cab9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676b73682f6269746d61736b2e737667)](https://packagist.org/packages/gksh/bitmask)[![GitHub Tests Action Status](https://camo.githubusercontent.com/aeb81a77ffe8ffa2121ccb103bac83030b78230b391f5adf08b1e9f79bf11e5f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646f74676b73682f6269746d61736b2f74657374732e796d6c3f6272616e63683d6d61696e)](https://github.com/dotgksh/bitmask/actions?query=workflow%3Atests+branch%3Amain)[![License](https://camo.githubusercontent.com/1fe9a6d8bd368c34c4317fe9e14a07644ee56ddd98a3cd53e43335290aecf7c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f676b73682f6269746d61736b2e737667)](https://github.com/dotgksh/bitmask/blob/main/LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/e7fd7a63c8d79e95f5516822831b760e25a155866dd3557d8ff7437453ce4ab2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676b73682f6269746d61736b2e737667)](https://packagist.org/packages/gksh/bitmask)

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

[](#installation)

> **Requires [PHP 8.2+](https://php.net/releases/)**

```
composer require gksh/bitmask
```

Usage
-----

[](#usage)

Streamline flag handling by encoding boolean options into simple integers through bitmasking.

> Please see [ide.php](./playground/ide.php) for full example and [playground](./playground) for more.

```
use Gksh\Bitmask\Bitmask;

enum Panel: int
{
    case Project = 1;
    case Terminal = 2;
    case SourceControl = 4;
    case Extensions = 8;
}

class Ide
{
    public Bitmask $panels;

    public function __construct()
    {
        $this->panels = Bitmask::tiny(); // 8-bit
    }

    public function togglePanel(Panel $panel): self
    {
        $this->panels = $this->panels->toggle($panel);

        return $this;
    }
}

$ide = (new Ide())
    ->togglePanel(Panel::Project)
    ->togglePanel(Panel::Terminal);

$ide->panels->has(Panel::Terminal); // true
$ide->panels->has(Panel::Extensions); // false
```

### Features

[](#features)

- **Immutable**: Operations return new instances, original unchanged
- **Enum support**: Pass `BackedEnum` directly — no `->value` extraction needed
- **Size variants**: `tiny()` (8-bit), `small()` (16-bit), `medium()` (24-bit), `make()` (32-bit default)

### Factory Methods

[](#factory-methods)

```
Bitmask::make()         // 32-bit (default)
Bitmask::tiny()         // 8-bit, for TINYINT columns
Bitmask::small()        // 16-bit, for SMALLINT columns
Bitmask::medium()       // 24-bit, for MEDIUMINT columns
```

### Operations

[](#operations)

```
$mask = Bitmask::tiny()
    ->set(Flag::A)      // Set a flag
    ->unset(Flag::B)    // Unset a flag
    ->toggle(Flag::C);  // Toggle a flag

$mask->has(Flag::A);    // Check if flag is set
$mask->value();         // Get integer value
$mask->size();          // Get Size enum
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Gustavo Karkow](https://github.com/karkowg)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance77

Regular maintenance activity

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~618 days

Total

2

Last Release

126d ago

Major Versions

v0.0.1 → v1.0.02026-01-12

PHP version history (2 changes)v0.0.1PHP ^8.2.0

v1.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1a8ad2e8cad0e133fd62d56397d613fc11abcf9482502d402f2696b45a079d8?d=identicon)[karkowg](/maintainers/karkowg)

---

Top Contributors

[![karkowg](https://avatars.githubusercontent.com/u/14905932?v=4)](https://github.com/karkowg "karkowg (8 commits)")

---

Tags

binarybitfieldbitflagbitmaskbitwisephpphpbinarybitmaskbitwisebitfieldbit flags

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gksh-bitmask/health.svg)

```
[![Health](https://phpackages.com/badges/gksh-bitmask/health.svg)](https://phpackages.com/packages/gksh-bitmask)
```

###  Alternatives

[yaroslavche/bitmask

BitMask, EnumBitMask

3453.7k1](/packages/yaroslavche-bitmask)[reinder83/binary-flags

Useful class for binary operations

1374.5k](/packages/reinder83-binary-flags)[ramazancetinkaya/byte-formatter

A modern PHP library for formatting and parsing byte values with precision and flexibility.

144.0k](/packages/ramazancetinkaya-byte-formatter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
