PHPackages                             phlak/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. phlak/config

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

phlak/config
============

Config loading and management

8.0.0(2y ago)59315.7k—8.9%10[3 PRs](https://github.com/PHLAK/Config/pulls)10MITPHPPHP ^8.0 || ^8.1 || ^8.2CI passing

Since Aug 21Pushed 2y ago4 watchersCompare

[ Source](https://github.com/PHLAK/Config)[ Packagist](https://packagist.org/packages/phlak/config)[ GitHub Sponsors](https://github.com/sponsors/PHLAK)[ Fund](https://paypal.me/ChrisKankiewicz)[ RSS](/packages/phlak-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (17)Used By (10)

 [![Config](config.png)](config.png)

 [![Join our Community](https://camo.githubusercontent.com/073a08ec4c3c801a8e24c53184d95a6562d74582854cb46320bcd76ef48ea543/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e5f7468652d436f6d6d756e6974792d3762313666662e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/PHLAK/Config/discussions) [![Become a Sponsor](https://camo.githubusercontent.com/00da07edf5fbff7528a4743d85563603f9284f02680e0ab1e73652e680878548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d655f612d53706f6e736f722d6363343139352e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/users/PHLAK/sponsorship) [![One-time Donation](https://camo.githubusercontent.com/e9b5aa71ffdb17943c10c6d6b4a3132b66a938495331e488ecbdad1f3c078879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616b655f612d446f6e6174696f6e2d3030366262362e7376673f7374796c653d666f722d7468652d6261646765)](https://paypal.me/ChrisKankiewicz)
 [![Latest Stable Version](https://camo.githubusercontent.com/8db785b8c05ba7d0108a5fe3b0e48bd088c9d65973b2d51527474bbb77db7d2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f50484c414b2f436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Config) [![Total Downloads](https://camo.githubusercontent.com/b037b622beacc45743804340d6dd67cf7f5fdf160191a741ac01cb4493080d03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f50484c414b2f436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Config) [![License](https://camo.githubusercontent.com/98329e5e6f67af0372996f025513de27b7aa36fb67121e6bd29200f9b177aeba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f50484c414b2f436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Config) [![](https://camo.githubusercontent.com/ed0444f0805b4fa27fb4d6afcea7e77ebd0cbe9a2fde9b000a36f73097b39316/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50484c414b2f436f6e6669672f746573742d73756974652e79616d6c3f7374796c653d666c61742d737175617265)](https://github.com/PHLAK/Config/actions/workflows/test-suite.yaml)

 PHP library for simple configuration management -- Created by [Chris Kankiewicz](https://www.ChrisKankiewicz.com) ([@PHLAK](https://twitter.com/PHLAK))

---

Introduction
------------

[](#introduction)

Config is a simple PHP configuration management library supporting multiple configuration file formats and an expressive API.

Supported file formats:

- PHP
- INI
- JSON
- [TOML](https://github.com/toml-lang/toml)
- YAML
- XML

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

[](#requirements)

- [PHP](https://php.net) &gt;= 7.1

Install with Composer
---------------------

[](#install-with-composer)

```
composer require phlak/config
```

Initializing the Client
-----------------------

[](#initializing-the-client)

First, import Config:

```
use PHLAK\Config\Config;
```

Then instantiate the class:

```
$config = new Config($context, $prefix = null);
```

Where `$context` is one of the following:

- A path to a supported file type
- A directory path containing one or more supported file types
- An array of configuration options

And `$prefix` is a string to be used as a key prefix for options of this Config object.

Configuration File Formats
--------------------------

[](#configuration-file-formats)

### PHP

[](#php)

A PHP configuration file must have the `.php` file extension, be a valid PHP file and and return a valid PHP array.

 Example PHP file```

    mysql

            database.sqlite

            localhost
            blog
            blogger
            hunter2
            utf8

```

Usage
-----

[](#usage)

### \_\_construct

[](#__construct)

> Create a new Config object.

```
Config::__construct( mixed $context [, string $prefix = null ] ) : Config
```

 `$context` Raw array of configuration options or path to a configuration file or directory containing one or more configuration files `$prefix` A key under which the loaded config will be nested#### Examples

[](#examples)

Create a new Config object from a YAML file.

```
$config = new Config('path/to/conifg.yaml');
```

Create a new Config object from a directory of config files.

```
$config = new Config('path/to/conifgs/');
```

Create a new Config object from an array.

```
$config = new Config([
    'hostname' => 'localhost',
    'port' => 12345
]);
```

---

### set

[](#set)

> Store a config value with a specified key.

```
Config::set( string $key, mixed $value ) : bool
```

 `$key` Unique configuration option key `$value` Config item value#### Example

[](#example)

```
$config->set('hostname', 'localhost');
$config->set('port', 12345);
```

---

### get

[](#get)

> Retrieve a configuration option via a provided key.

```
Config::get( string $key [, mixed $default = null ] ) : mixed
```

 `$key` Unique configuration option key `$value` Config item value#### Examples

[](#examples-1)

```
// Return the hostname option value or null if not found.
$config->get('hostname');
```

Define a default value to return if the option is not set.

```
// Returns 'localhost' if hostname option is not set
$config->get('hostname', 'localhost');
```

---

### has

[](#has)

> Check for the existence of a configuration item.

```
Config::has( string $key ) : bool
```

 `$key` Unique configuration option key#### Example

[](#example-1)

```
$config = new Config([
    'hostname' => 'localhost'
]);

$config->has('hostname'); // Returns true
$config->has('port');     // Returns false
```

---

### append

[](#append)

> Append a value onto an existing array configuration option.

```
Config::append( string $key, mixed $value ) : bool
```

 `$key` Unique configuration option key `$value` Config item value#### Example

[](#example-2)

Append `baz` to the `tags` config item array.

```
$config->set('tags', ['foo', 'bar'])
$config->append('tags', 'baz'); // ['foo', 'bar', 'baz']
```

---

### prepend

[](#prepend)

> Prepend a value onto an existing array configuration option.

```
Config::append( string $key, mixed $value ) : bool
```

 `$key` Unique configuration option key `$value` Config item value#### Example

[](#example-3)

Prepend `baz` to the `tags` config item array.

```
$config->set('tags', ['foo', 'bar'])
$config->append('tags', 'baz'); // ['baz', 'foo', 'bar']
```

---

### unset

[](#unset)

> Unset a configuration option via a provided key.

```
Config::unset( string $key ) : bool
```

 `$key` Unique configuration option key#### Example

[](#example-4)

```
$config->unset('hostname');
```

---

### load

[](#load)

> Load configuration options from a file or directory.

```
Config::load( string $path [, string $prefix = null [, bool $override = true ]] ) : self
```

 `$path` Path to configuration file or directory `$prefix` A key under which the loaded config will be nested `$override` Whether or not to override existing options with values from the loaded file#### Examples

[](#examples-2)

Load a single additional file.

```
$conifg->load('path/to/config.php');
```

Load an additional file with a prefix.

```
$config->load('databaes.php', 'database');
```

Load an additional file without overriding existing values.

```
$config->load('additional-options.php', null, false);
```

---

### merge

[](#merge)

> Merge another Config object into this one.

```
Config::merge( Config $config [, bool $override = true ] ) : self
```

 `$config` Instance of Config `$override` Whether or not to override existing options with values from the merged config object#### Examples

[](#examples-3)

Merge $anotherConfig into $config and override values in `$config` with values from `$anotherConfig`.

```
$anotherConfig = new Config('some/config.php');

$config->merge($anotherConfig);
```

Merge `$anotherConfig` into `$config` without overriding any values. Duplicate values in `$anotherConfig` will be lost.

```
$anotherConfig = new Config('some/config.php');

$config->merge($anotherConfig, false);
```

---

### split

[](#split)

> Split a sub-array of configuration options into it's own Config object.

```
Config::split( string $key ) : Config
```

 `$key` Unique configuration option key#### Example

[](#example-5)

```
$config = new Config([
    'foo' => 'foo',
    'bar' => [
        'baz' => 'barbaz'
    ],
]);

$barConfig = $config->split('bar');

$barConfig->get('baz');  // Returns 'barbaz'
```

---

### toArray

[](#toarray)

> Return the entire configuration as an array.

```
Config::toArray( void ) : array
```

#### Example

[](#example-6)

```
$config = new Config(['foo' => 'foo']);

$config->toArray(); // Returns ['foo' => 'foo']
```

---

Troubleshooting
---------------

[](#troubleshooting)

For general help and support join our [GitHub Discussion](https://github.com/PHLAK/Config/discussions) or reach out on [Twitter](https://twitter.com/PHLAK).

Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/Config/issues).

Copyright
---------

[](#copyright)

This project is liscensed under the [MIT License](https://github.com/PHLAK/Config/blob/master/LICENSE).

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 90.3% 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 ~202 days

Recently: every ~493 days

Total

14

Last Release

930d ago

Major Versions

3.0.1 → 4.0.02018-03-30

4.0.0 → 5.0.02018-06-07

5.0.0 → 6.0.02018-08-04

6.1.0 → 7.0.02020-03-16

7.0.0 → 8.0.02023-10-31

PHP version history (6 changes)0.1.0PHP &gt;=5.4

1.0.0PHP &gt;=5.5.9

2.0.0PHP &gt;=5.6

5.0.0PHP &gt;=7.0

6.0.0PHP &gt;=7.1

8.0.0PHP ^8.0 || ^8.1 || ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53531?v=4)[Chris Kankiewicz](/maintainers/PHLAK)[@PHLAK](https://github.com/PHLAK)

---

Top Contributors

[![PHLAK](https://avatars.githubusercontent.com/u/53531?v=4)](https://github.com/PHLAK "PHLAK (159 commits)")[![Externaluse](https://avatars.githubusercontent.com/u/14993667?v=4)](https://github.com/Externaluse "Externaluse (10 commits)")[![brutto](https://avatars.githubusercontent.com/u/954379?v=4)](https://github.com/brutto "brutto (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

configconfig-managementinijsonphpphp-libraryxmlyaml

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sspooky13/yaml-standards

Standards for yaml files

11518.3k3](/packages/sspooky13-yaml-standards)[hyn/frontmatter

Markdown including meta information parsing from frontmatters

1038.2k3](/packages/hyn-frontmatter)[prohalexey/the-choice

253.3k](/packages/prohalexey-the-choice)[opensoft/simple-serializer

Simple Serializer

1914.2k1](/packages/opensoft-simple-serializer)[phppkg/config

Config manage, load, get. Supports INI,JSON,YAML,NEON,PHP format file

133.5k](/packages/phppkg-config)

PHPackages © 2026

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