PHPackages                             adamnicholson/bag - 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. adamnicholson/bag

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

adamnicholson/bag
=================

A simple parameter bag to make working with arrays easier

v2.0.1(3y ago)233.6k↓38.3%11MITPHPPHP &gt;=8.0

Since Nov 15Pushed 3y agoCompare

[ Source](https://github.com/adamnicholson/bag)[ Packagist](https://packagist.org/packages/adamnicholson/bag)[ RSS](/packages/adamnicholson-bag/feed)WikiDiscussions master Synced 1mo ago

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

Bag
===

[](#bag)

*Bag* is a simple parameter bag class to make working with arrays easier.

[![Build Status](https://camo.githubusercontent.com/c75cc59f2ac6089678d6c662191157e963a69bc926b8037fd7ff303d3da5d910/68747470733a2f2f7472617669732d63692e6f72672f6164616d6e6963686f6c736f6e2f6261672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/adamnicholson/bag)

Motivation
----------

[](#motivation)

Boilerplate `isset` calls whenever working with arrays can be a pain.

```
function foo (array $data) {
    if (!isset($data['status']) || !isset($data['data']['foo'])) || $data['status'] !== 'success') {
        return false;
    }
    return $data['data']['foo'];
}

// vs

function bar (array $data) {
    $data = new Bag($data);

    if ($bag->get('status') !== 'success') {
        return false;
    }

    return $bag->get('data.foo');
}
```

> Note: `isset` boilerplate will hopefully be much less of a chore in PHP7 with the [isset ternary operator](https://wiki.php.net/rfc/isset_ternary)

Usage
-----

[](#usage)

```
$array = [
    'foo' => 'bar',
    'hello' => 'world',
    'items' => [
        'first' => 'fizz',
        'second' => 'buzz'
    ]
];

$bag = new Adam\Bag\Bag($array);

// Get a value by key
$bag->get('foo'); // string "bar"

// Set some value by key
$bag->set('fizz', 'buzz');

// Return a default value if the key is not set
$bag->get('ziff'); // null
$bag->get('ziff', 'my_default_value'); // string "my_default_value"

// Use dot notation for multidimensional arrays
$bag->get('items.first'); // string "fizz"
$bag->set('items.third', 'foovalue');

// Get the value of an item and then remove it
$bag->pluck('foo'); // string "bar"
$bag->get('foo'); // null

// Get the raw data
$bag->all(); // array

// Empty the data
$bag->flush();

// Or just use it like an array
$bag['foo'] = 'bar';
$bag['foo']; // string "bar"
$bag->get('foo'); // string "bar"
```

Contributing
------------

[](#contributing)

We welcome any contributions to this project. They can be made via GitHub issues or pull requests.

License
-------

[](#license)

This project is licensed under the MIT License - see the `LICENSE.txt` file for details

Author
------

[](#author)

Adam Nicholson -

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Total

2

Last Release

1280d ago

PHP version history (2 changes)v2.0PHP &gt;=7.4

v2.0.1PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adamnicholson-bag/health.svg)

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

PHPackages © 2026

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