PHPackages                             initphp/parameterbag - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. initphp/parameterbag

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

initphp/parameterbag
====================

Single and multi-dimensional parameter bag with dot-path access for PHP.

2.0.0(1mo ago)22616MITPHPPHP ^7.4 || ^8.0CI passing

Since Mar 14Pushed 3w ago1 watchersCompare

[ Source](https://github.com/InitPHP/ParameterBag)[ Packagist](https://packagist.org/packages/initphp/parameterbag)[ RSS](/packages/initphp-parameterbag/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (3)Versions (10)Used By (6)

InitPHP ParameterBag
====================

[](#initphp-parameterbag)

A small, dependency-free parameter container for PHP that handles both flat and nested (dotted-path) data with the same API.

[![Latest Stable Version](https://camo.githubusercontent.com/59840af4247b57f01c835e1ca7398663fd864ee2c2e375f6ac5b0957c34843ae/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f706172616d657465726261672f76)](https://packagist.org/packages/initphp/parameterbag)[![Total Downloads](https://camo.githubusercontent.com/4eafb2423fc61934c665242ca19fe923612441d1f3518ee2b0fd6f487787f33a/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f706172616d657465726261672f646f776e6c6f616473)](https://packagist.org/packages/initphp/parameterbag)[![CI](https://github.com/InitPHP/ParameterBag/actions/workflows/ci.yml/badge.svg)](https://github.com/InitPHP/ParameterBag/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/fd946372fc274ee5487d044085c2eb87025b819f83b8702c8023b50218642660/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f706172616d657465726261672f6c6963656e7365)](https://packagist.org/packages/initphp/parameterbag)[![PHP Version Require](https://camo.githubusercontent.com/968328212e53c566bb857f83555f514226aee64a9b02726938d377d08205cfed/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f706172616d657465726261672f726571756972652f706870)](https://packagist.org/packages/initphp/parameterbag)

[![parameterbag](https://camo.githubusercontent.com/ad6634db18922ce000b52cc07f12c7ada26457027fcc1372e35c53c1162acbfe/68747470733a2f2f696e69747068702e6769746875622e696f2f6c6f676f732f706172616d657465726261672e706e67)](https://camo.githubusercontent.com/ad6634db18922ce000b52cc07f12c7ada26457027fcc1372e35c53c1162acbfe/68747470733a2f2f696e69747068702e6769746875622e696f2f6c6f676f732f706172616d657465726261672e706e67)

---

Features
--------

[](#features)

- Single API for flat and nested data; nesting is auto-detected from the constructor payload or toggled explicitly.
- Dotted-path access (`$bag->get('database.user')`) with a configurable separator.
- Optional, opt-in case-insensitive key handling.
- Implements PHP's standard collection contracts: `ArrayAccess`, `Countable`, `IteratorAggregate`.
- Strict validation of constructor options (typos throw instead of being silently ignored).
- Zero runtime dependencies; PHPStan level 8 clean.

Requirements
------------

[](#requirements)

- PHP 7.4 or later (including 8.0–8.4)

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

[](#installation)

```
composer require initphp/parameterbag
```

Quick start
-----------

[](#quick-start)

```
use InitPHP\ParameterBag\ParameterBag;

$bag = new ParameterBag($_GET);

// GET /?user=alice
echo $bag->get('user', 'guest'); // 'alice'

$bag->set('locale', 'en_US')->set('debug', true);
$bag->has('debug');              // true
$bag->remove('debug');
```

### Nested data (multi mode)

[](#nested-data-multi-mode)

Pass a nested array (or set `isMulti => true` explicitly) and the bag will treat the separator (`.` by default) as a path delimiter:

```
$config = new ParameterBag([
    'database' => [
        'dsn'      => 'mysql:host=localhost',
        'username' => 'root',
        'password' => 'secret',
    ],
]);

$config->get('database.username');   // 'root'
$config->has('database.charset');    // false
$config->set('database.charset', 'utf8mb4');
$config->remove('database.password');
```

Use a custom separator if dots are part of your keys:

```
$bag = new ParameterBag($data, ['separator' => '|']);
$bag->get('database|username');
```

### Native PHP idioms

[](#native-php-idioms)

```
$bag = new ParameterBag(['a' => 1, 'b' => 2]);

count($bag);          // 2
$bag['c'] = 3;        // ArrayAccess write
isset($bag['c']);     // true
foreach ($bag as $key => $value) { /* ... */ }
```

Public API
----------

[](#public-api)

MethodPurposeDocs`get(string $key, mixed $default = null): mixed`Look up a value (dotted paths in multi mode).[usage/basic-usage](docs/usage/basic-usage.md)`has(string $key): bool`Existence check (null values count as present).[usage/basic-usage](docs/usage/basic-usage.md)`set(string $key, mixed $value): self`Assign or replace a value.[usage/basic-usage](docs/usage/basic-usage.md)`remove(string ...$keys): self`Delete one or more keys.[usage/basic-usage](docs/usage/basic-usage.md)`merge(array|ParameterBagInterface ...$payloads): self`Shallow merge (flat) or recursive replace (multi).[usage/merging](docs/usage/merging.md)`replace(array $data): self`Swap the entire stack.[api-reference](docs/api-reference.md)`all(): array`Return the current stack as a plain array.[api-reference](docs/api-reference.md)`keys(): array` / `values(): array`Top-level keys / values in insertion order.[api-reference](docs/api-reference.md)`count(): int`Top-level entry count (also via `count($bag)`).[usage/iteration-and-counting](docs/usage/iteration-and-counting.md)`getIterator(): ArrayIterator`Iterates top-level entries.[usage/iteration-and-counting](docs/usage/iteration-and-counting.md)`isEmpty(): bool`True when the stack has no entries.[api-reference](docs/api-reference.md)`clear(): void`Empty the stack, keep options.[api-reference](docs/api-reference.md)`close(): void`Empty the stack and reset options to defaults.[api-reference](docs/api-reference.md)Configuration options
---------------------

[](#configuration-options)

The constructor accepts a second array of options. Unknown keys raise `ParameterBagInvalidArgumentException`.

KeyTypeDefaultDescription`isMulti``bool`auto-detected from `$data`Enables dotted-path semantics.`separator``non-empty-string``'.'`Delimiter for dotted paths. Ignored in flat mode.`caseInsensitive``bool``false`When true, every key (constructor payload, set/get/has/remove arguments, merge input) is folded to lower-case. Matches the legacy v1 behaviour.See [docs/configuration.md](docs/configuration.md) and [docs/usage/case-sensitivity.md](docs/usage/case-sensitivity.md).

Exceptions
----------

[](#exceptions)

ExceptionRaised when`InitPHP\ParameterBag\Exception\ParameterBagInvalidArgumentException`Unknown option key, non-array/non-ParameterBag argument to `merge()`, or `$bag[] = $v` ArrayAccess append. Extends `\InvalidArgumentException`.See [docs/exceptions.md](docs/exceptions.md).

Development
-----------

[](#development)

```
composer install
composer test         # PHPUnit
composer analyse      # PHPStan (level 8)
composer cs:check     # PHP-CS-Fixer dry-run
composer cs:fix       # PHP-CS-Fixer apply
```

CI runs the matrix across PHP 7.4, 8.0, 8.1, 8.2, 8.3, and 8.4.

Upgrading from v1
-----------------

[](#upgrading-from-v1)

v2 introduces a small set of intentional behaviour changes (cache removed, `isMulti` auto-detect inverted, value-trim bug fixed, case-sensitive by default, strict option validation, new methods). A full migration guide lives at [docs/upgrading-from-v1.md](docs/upgrading-from-v1.md).

Contributing &amp; Security
---------------------------

[](#contributing--security)

- [Contributing guidelines](https://github.com/InitPHP/.github/blob/main/CONTRIBUTING.md)
- [Code of Conduct](https://github.com/InitPHP/.github/blob/main/CODE_OF_CONDUCT.md)
- [Security policy](https://github.com/InitPHP/.github/blob/main/SECURITY.md)

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Released under the [MIT License](./LICENSE).

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Recently: every ~319 days

Total

9

Last Release

40d ago

Major Versions

1.x-dev → 2.x-dev2026-05-24

PHP version history (3 changes)1.0PHP &gt;=7.4

1.1PHP &gt;=7.2

2.x-devPHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (10 commits)")

---

Tags

arrayaccessconfigconfigurationcontainerdot-notationinitphpnested-dataparameter-bagphpphp74php8containerconfigdot notationinitphpparameter-bag

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/initphp-parameterbag/health.svg)

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

###  Alternatives

[psr/container

Common Container Interface (PHP FIG PSR-11)

10.0k1.1B4.7k](/packages/psr-container)[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k134.5M1.4k](/packages/pimple-pimple)[php-di/php-di

The dependency injection container for humans

2.9k55.5M1.2k](/packages/php-di-php-di)[league/container

A fast and intuitive dependency injection container.

86894.4M442](/packages/league-container)[michaels/data-manager

Simple data manager for nested data, dot notation array access, extendability, and container interoperability.

132.0k2](/packages/michaels-data-manager)

PHPackages © 2026

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