PHPackages                             rb-cohen/php-env - 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. rb-cohen/php-env

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

rb-cohen/php-env
================

Envrionment variable helper

1.1.0(3y ago)02.9kMITPHP

Since Sep 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/rb-cohen/php-env)[ Packagist](https://packagist.org/packages/rb-cohen/php-env)[ RSS](/packages/rb-cohen-php-env/feed)WikiDiscussions master Synced 2d ago

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

php-env
=======

[](#php-env)

Useful function for getting envrionment varibles for config, with a default fallback if the variable is not set.

Functions
---------

[](#functions)

### env($name, $default = null)

[](#envname-default--null)

Looks for an environment variable called `$name`, returning `$default` if the variable is not available.

`$default` can be an anonymous function, which will be called to obtain a value if the environment variable is not set.

Strings 'true', 'false' and 'null' will be converted to their PHP types `true`, `false` and `null`.

### env\_to\_array($name, $default = array())

[](#env_to_arrayname-default--array)

Similar to env, calls env internally, but will split the env variable or default value in to an array by comma.

Also trims the array values.

### resolve\_value($value)

[](#resolve_valuevalue)

Used by `env()` to recursively call anonymous functions to resolve a value if the variable is not set.

Examples
--------

[](#examples)

### Basic config

[](#basic-config)

```
$config = [
  'mysql' => [
    'host' => env('DB_HOST', 'localhost'),
    'username' => env('DB_USERNAME', 'dbuser'),
    'password' => env('DB_PASSWORD'),
    'dbname' => env('DB_NAME', 'my_database'),
  ]
];
```

### Using an anonymous function

[](#using-an-anonymous-function)

```
$username = env('USER', function(){
  return exec('whoami');
});
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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

Total

2

Last Release

1442d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/203873940?v=4)[rb-cohen](/maintainers/rb-cohen)[@rb-cohen](https://github.com/rb-cohen)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rb-cohen-php-env/health.svg)

```
[![Health](https://phpackages.com/badges/rb-cohen-php-env/health.svg)](https://phpackages.com/packages/rb-cohen-php-env)
```

###  Alternatives

[tastaturberuf/anystores

Location management and geographic search

111.7k](/packages/tastaturberuf-anystores)

PHPackages © 2026

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