PHPackages                             hambrook/config - 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. hambrook/config

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

hambrook/config
===============

Easy-to-work-with config object that saves to a JSON file.

v1.0.5(10y ago)0341GPL-3.0PHP

Since Oct 20Pushed 10y ago1 watchersCompare

[ Source](https://github.com/hambrook/config)[ Packagist](https://packagist.org/packages/hambrook/config)[ RSS](/packages/hambrook-config/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

\#Config

A simple Config object that loads a JSON file and lets you access values without having to check if they're set first. Then automatically saves back to the JSON file when your script finishes. It inherits all the getting/setting abilities from [Nest](https://github.com/Hambrook/Nest).

\##Example

```
$Config = new \Hambrook\Config\Config("settings.json");
```

JSON File (settings.json)

```
{
	"foo": "bar",
	"one": {
		"two": "three"
	}
};
```

\####Use a string as the path parameter

```
$value = $Config->get("foo");
// "bar"
```

\####We're going two levels in this time, so use an array for the path

```
$value = $Config->get(["one", "two"]);
// "three"
```

\####What if we try to get something that isn't there? Does it error?

```
$value = $Config->get(["nope", "two"]);
// returns `null`, not an error
```

\####Or we can specify our own default in case of error

```
$value = $Config->get(["nope", "two"], "safe");
// returns "safe", not an error
```

\##Saving By default, Config will auto-save at the end of the script. If you instanciate Config with `false` as the second parameter, then it will no longer auto-save.

You can save at any time by using the `save()` function.

```
// Save the JSON encoded data to the file and returns `$this`
$Config->save();
```

\##Shortcuts You can use `__` (by default) as a separator instead of using an array, then you can do things like...

```
// Get a nested value
$value = Config->one__two
// "three"

// Get a nested value that isn't there
$value = Config->one__bad
// null

// Get a nested value, with a default if the value isn't there
$value = Config->one__bad("default")
// "default"

// Get a nested value, with a default if the value isn't there
$value = Config->one__two = "newthree"
// sets the value to "newthree" then returns `$this`
```

\##Who is it for? Config was built for small CLI scripts and tools. But it can be used anywhere.

\##Feedback Tell me if you loved it. Tell me if you hated it. Tell me if you used it and thought "meh". I'm keen to hear your feedback.

\##Roadmap

- Add any other standard documentation that should be included
- Add proper unit tests
- *If you have an idea, [let me know](https://github.com/Hambrook/Config/issues).*

\##License Copyright © 2015 Rick Hambrook

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity64

Established project with proven stability

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

Unknown

Total

1

Last Release

3910d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/85ada3ce00da731d5a3883600d5fad778340eaea5a1e96a227aaed62256008cd?d=identicon)[Hambrook](/maintainers/Hambrook)

---

Tags

phpjsonarrayobjectsaving

### Embed Badge

![Health badge](/badges/hambrook-config/health.svg)

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

###  Alternatives

[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k13.2M174](/packages/cuyz-valinor)[zakirullin/mess

Convenient array-related routine &amp; better type casting

21330.5k2](/packages/zakirullin-mess)[hi-folks/data-block

Data class for managing nested arrays and JSON data.

1462.9k](/packages/hi-folks-data-block)

PHPackages © 2026

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