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

ActiveLibrary

miladm/config
=============

This package will create simple config handler for projects

1.0.1(3y ago)07MITPHPPHP &gt;=8.2

Since Feb 12Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (3)Used By (0)

Config class
============

[](#config-class)

The `Config` class provides a simple way to manage configuration settings for your PHP application. You can initialize the `Config` object with an object, array, or file path containing your configuration data, and then retrieve individual configuration values using the `get()` method.

Basic usage
-----------

[](#basic-usage)

To get started with the `Config` class, create a new instance of the class by passing in your configuration data:

```
use miladm\Config;

$config = new Config([
    'db_host' => 'localhost',
    'db_port' => 3306,
    'db_user' => 'myuser',
    'db_pass' => 'mypass',
    'db_name' => 'mydb',
]);
```

You can then retrieve individual configuration values using the get() method:

```
$host = $config->get('db_host');
$port = $config->get('db_port');
$user = $config->get('db_user');
$pass = $config->get('db_pass');
$name = $config->get('db_name');
```

If a configuration value is not found, the get() method will return null.

Using environment variables
---------------------------

[](#using-environment-variables)

You can also retrieve configuration values from environment variables. If an environment variable is defined with the same name as a configuration key, the get() method will return the value of the environment variable instead of the value from the configuration data. For example:

```
putenv('DB_HOST=localhost');
putenv('DB_PORT=3306');
putenv('DB_USER=myuser');
putenv('DB_PASS=mypass');
putenv('DB_NAME=mydb');

$host = $config->get('db_host'); // returns 'localhost'
$port = $config->get('db_port'); // returns 3306
$user = $config->get('db_user'); // returns 'myuser'
$pass = $config->get('db_pass'); // returns 'mypass'
$name = $config->get('db_name'); // returns 'mydb'
```

[more about environemt variables in different environments](more_about_environment.md)

Magic properties
----------------

[](#magic-properties)

The Config class also supports retrieving configuration values using magic properties. If a property with the same name as a configuration key is accessed, the \_\_get() magic method will be called, which is equivalent to calling the get() method. For example:

```
$host = $config->db_host;
$port = $config->db_port;
$user = $config->db_user;
$pass = $config->db_pass;
$name = $config->db_name;
```

Caching
-------

[](#caching)

To improve performance, the Config class caches retrieved values in an internal array. This means that subsequent calls to get() for the same configuration key will return the cached value instead of re-fetching it from the configuration data or environment variables. If you need to clear the cache for a particular key, you can do so by setting the corresponding value in the internal cache array to null. For example:

```
$config->get('db_host'); // fetches from configuration data or environment variables and caches the value
$config->cache['db_host'] = null; // clears the cache for the 'db_host' key
$config->get('db_host'); // fetches from configuration data or
```

environment variables again and caches the value

Error handling
--------------

[](#error-handling)

If your configuration data is not valid, the Config constructor will throw an exception. For example, if you pass in a string that is not a valid file path or JSON string, or an object or array with non-string keys, an exception will be thrown with an appropriate

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

1192d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/22d33b0e34bc66cae7ab5a979b15f2975bb87dd73d1cfa2255dae95302799d75?d=identicon)[MiladM](/maintainers/MiladM)

---

Top Contributors

[![MiladMohebnia](https://avatars.githubusercontent.com/u/6062074?v=4)](https://github.com/MiladMohebnia "MiladMohebnia (3 commits)")

### Embed Badge

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

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

PHPackages © 2026

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