PHPackages                             icecave/flip - 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. icecave/flip

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

icecave/flip
============

A tiny library for working with strict sets of boolean values.

0.2.0(10y ago)25231[1 PRs](https://github.com/IcecaveStudios/flip/pulls)MITPHPPHP &gt;=5.5

Since Nov 17Pushed 10y ago1 watchersCompare

[ Source](https://github.com/IcecaveStudios/flip)[ Packagist](https://packagist.org/packages/icecave/flip)[ Docs](https://github.com/IcecaveStudios/flip)[ RSS](/packages/icecave-flip/feed)WikiDiscussions develop Synced 1mo ago

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

Flip
====

[](#flip)

[![The most recent stable version is 0.2.0](https://camo.githubusercontent.com/196c1bbf5131f8972f92a6e32df0de5aa5331b79f15f1c23382d934e1d58e55d/687474703a2f2f696d672e736869656c64732e696f2f3a73656d7665722d302e322e302d79656c6c6f772e7376673f7374796c653d666c61742d737175617265 "This project uses semantic versioning")](http://semver.org/)[![Current build status image](https://camo.githubusercontent.com/74606e2b148a85a1b9a9e7a0937383640a5b76d377a2efd69885fe61e6cb81ae/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f4963656361766553747564696f732f666c69702f646576656c6f702e7376673f7374796c653d666c61742d737175617265 "Current build status for the develop branch")](https://travis-ci.org/IcecaveStudios/flip)[![Current coverage status image](https://camo.githubusercontent.com/3b663be0dbc6f26070c81309aaf6fc8b0f0e76de9f3c34aacfdb3bf3ee5fda8d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f4963656361766553747564696f732f666c69702f646576656c6f702e7376673f7374796c653d666c61742d737175617265 "Current test coverage for the develop branch")](https://coveralls.io/r/IcecaveStudios/flip)

**Flip** is a tiny PHP library for working with strict sets of boolean flags.

- Install via [Composer](http://getcomposer.org/) package [icecave/flip](https://packagist.org/packages/icecave/flip)
- Read the [API documentation](http://icecavestudios.github.io/flip/artifacts/documentation/api/)

Defining a flag-set
-------------------

[](#defining-a-flag-set)

A flag-set describes the available flags of a given type. Flag-sets are defined by declaring a class that uses the `FlagSetTrait` trait.

Each property in the class defines a named flag that can be set to `true` or `false`. All properties must be private and have a default boolean value.

```
use Icecave\Flip\FlagSetTrait;

final class ExampleFlags
{
    use FlagSetTrait;

    private $foo = true;
    private $bar = false;
    private $baz = false;
}
```

Creating a flag-set
-------------------

[](#creating-a-flag-set)

The flag-set trait provides the following static methods for quickly creating common sets:

- `defaults()` - creates a flag-set where all flags are set to the default values
- `all()` - creates a flag-set where all flags are set to `true`
- `none()` - creates a flag-set where all flags are set to `false`

Flag-sets can also be created and modified using a fluent interface. The example below creates a flag-set with only the `bar` and `baz` properties set to `true`.

```
$flags = ExampleFlags::none()
    ->bar(true)
    ->baz(true);
```

Omitting the initial call to `defaults()`, `all()` or `none()` is short-hand for using the defaults. This means that the following two examples are equivalent:

```
$flags = ExampleFlags::defaults()
    ->foo(false)
    ->bar(true);
```

```
$flags = ExampleFlags
    ::foo(false)
    ->bar(true);
```

Flag-sets are immutable, each call to the fluent interface returns a new instance with the updated flag value.

Flags can not be named "defaults", "all" or "none".

Using a flag-set
----------------

[](#using-a-flag-set)

**Functions that accept flag-sets as parameters can use a type-hint.** Flags are read using the regular PHP property notation. Flag values are guaranteed to be a boolean.

```
function dumpFlags(ExampleFlags $flags)
{
    if ($flags->foo) {
        echo 'Foo is enabled!';
    } else {
        echo 'Foo is disabled!';
    }

    if ($flags->bar) {
        echo 'Bar is enabled!';
    } else {
        echo 'Bar is disabled!';
    }

    if ($flags->baz) {
        echo 'Baz is enabled!';
    } else {
        echo 'Baz is disabled!';
    }
}
```

It is not possible to set flags using the property notation.

Contact us
----------

[](#contact-us)

- Follow [@IcecaveStudios](https://twitter.com/IcecaveStudios) on Twitter
- Visit the [Icecave Studios website](http://icecave.com.au/)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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 ~2 days

Total

2

Last Release

3833d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/93a71bd75fcd51efee464532dbdd54927cd00e938805998c76e0a804d38fa3fb?d=identicon)[jmalloc](/maintainers/jmalloc)

---

Top Contributors

[![jmalloc](https://avatars.githubusercontent.com/u/761536?v=4)](https://github.com/jmalloc "jmalloc (14 commits)")

---

Tags

enumsetoptionfieldflagbitboolean

### Embed Badge

![Health badge](/badges/icecave-flip/health.svg)

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

###  Alternatives

[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[myclabs/php-enum

PHP Enum implementation

2.7k227.9M637](/packages/myclabs-php-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49644.8M97](/packages/marc-mabe-php-enum)[dasprid/enum

PHP 7.1 enum implementation

382146.0M11](/packages/dasprid-enum)[spatie/enum

PHP Enums

84529.1M68](/packages/spatie-enum)[zumba/swivel

Strategy driven feature toggles

209135.7k5](/packages/zumba-swivel)

PHPackages © 2026

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