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

Abandoned → [sil-org/php-env](/?search=sil-org%2Fphp-env)Library[Utility &amp; Helpers](/categories/utility)

silinternational/php-env
========================

Simple PHP library for getting (or requiring) environment variables, designed to handle true, false, and null more intelligently. If desired, an environment variable's value can be split into an array automatically.

4.0.1(8mo ago)352.1k—3.8%20MITPHPPHP ^8.0CI passing

Since Oct 29Pushed 1mo ago8 watchersCompare

[ Source](https://github.com/sil-org/php-env)[ Packagist](https://packagist.org/packages/silinternational/php-env)[ RSS](/packages/silinternational-php-env/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (17)Used By (20)

Sil/PhpEnv/
===========

[](#silphpenv)

Simple PHP library for getting (or requiring) environment variables, designed to handle `true`, `false`, and `null` more intelligently. If desired, an environment variable's value can be split into an array automatically.

Build Status
------------

[](#build-status)

[![Unit Tests](https://github.com/sil-org/php-env/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/sil-org/php-env/actions/workflows/test.yml/badge.svg?branch=main)

Setup
-----

[](#setup)

1. Clone this repo.
2. Copy `local.env.dist` to `local.env` and update GitHub.com token as appropriate.
3. Run `make test` to install dependencies and run PHPUnit tests.

### Makefile script

[](#makefile-script)

There is a Makefile in place to simplify common tasks.

- `make test` - does `composer install` and runs phpunit tests

---

Classes in Sil/PhpEnv namespace
-------------------------------

[](#classes-in-silphpenv-namespace)

1. **Env**: `use Sil\PhpEnv\Env;`
2. **EnvVarNotFoundException**: `use Sil\PhpEnv\EnvVarNotFoundException;`

### Class `Env` summary of functions

[](#class-env-summary-of-functions)

1. **get** - `public static function get($varname, $default = null)`

    - searches the local environment for `$varname` and returns the corresponding value string
    - if `$varname` is not set or the value is empty (only whitespace), `get` returns `$default` parameter
    - if the value string corresponding to `$varname` is 'true', 'false' or 'null', `get` returns php values of `true`, `false`, or `null` respectively
    - NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php `true`.
        `false` and `null` are handled similarly. Other value strings will have leading/trailing whitespace trimmed.
2. **getString** - `public static function getString($varname, $default = null): ?string`

    - searches the local environment for `$varname` and returns the corresponding trimmed value string
    - if `$varname` is not set or the value is empty (only whitespace), `getString` returns `$default` parameter
3. **getBoolean** - `public static function getBoolean($varname, $default = null): ?bool`

    - searches the local environment for `$varname` and returns the corresponding boolean value string
    - if `$varname` is not set or the value is empty (only whitespace), `getBoolean` returns `$default` parameter
    - if the value string corresponding to `$varname` is 'true', 'false' or 'null', `getBoolean` returns php values of `true`, `false`, or `null` respectively
    - if the value is not boolean, `getBoolean` returns `$default` parameter
    - NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php `true`. `false` and `null` are handled similarly.
4. **getArray** - `public static function getArray($varname, array $default = [])`

    - searches the local environment for `$varname` and returns the corresponding value string with comma separated elements as a php array
    - if `$varname` is not set or the value is empty (only whitespace), `getArray` returns `$default` parameter which must be an array
    - if $default is not an array, it throws a `TypeError` exception
5. **requireEnv** - `public static function requireEnv($varname)`

    - searches the local environment for `$varname` and returns the corresponding value string
    - if `$varname` is not set or the value is empty (only whitespace), it throws `EnvVarNotFoundException`
    - 'true', 'false', and 'null' are handled the same as `get()`
6. **requireArray** - `public static function requireArray($varname)`

    - searches the local environment for `$varname` and returns the corresponding value string with comma separated elements as a php array
    - if `$varname` is not set or the value is empty (only whitespace), it throws `EnvVarNotFoundException`

### Class `EnvVarNotFoundException`

[](#class-envvarnotfoundexception)

`class EnvVarNotFoundException extends \Exception`

`EnvVarNotFoundException` is thrown by `requireEnv()` and `requireArray()` when `$varname` is not found in the local environment or the corresponding value string is empty (only whitespace)

---

`Env` example function calls
----------------------------

[](#env-example-function-calls)

### Assume this `local.env` file

[](#assume-this-localenv-file)

```
EMPTY=
SPACES=
WHITESPACE= Some whitespace
FALSE=False
TRUE=TRUE
NULL=null
LOWERCASE=abc123
UPPERCASE=ABC123
ARRAY0=
ARRAY1=one
ARRAY=one,two,,three

```

### Example function calls and results

[](#example-function-calls-and-results)

- **get** - `public static function get($varname, $default = null)`

    1. `Env::get('NOTFOUND')` - returns `null`
    2. `Env::get('NOTFOUND', 'bad data')` - returns `'bad data'`
    3. `Env::get('EMPTY')` - returns `''`
    4. `Env::get('SPACES')` - returns `''`
    5. `Env::get('WHITESPACE')` - returns `'Some whitespace'`
    6. `Env::get('FALSE')` - returns `false`
    7. `Env::get('TRUE')` - returns `true`
    8. `Env::get('NULL')` - returns `null`
    9. `Env::get('LOWERCASE')` - returns `'abc123'`
    10. `Env::get('UPPERCASE')` - returns `'ABC123'`
- **requireEnv** - `public static function requireEnv($varname)`

    1. `Env::requireEnv('NOTFOUND')` - throws `EnvVarNotFoundException`
    2. `Env::requireEnv('EMPTY')` - throws `EnvVarNotFoundException`
    3. `Env::requireEnv('WHITESPACE')` - returns `'Some whitespace'`
    4. `Env::requireEnv('FALSE')` - returns `false`
    5. `Env::requireEnv('LOWERCASE')` - returns `'abc123'`
- **getArray** - `public static function getArray($varname, array $default = [])`

    1. `Env::getArray('NOTFOUND')` - returns `[]`
    2. `Env::getArray('NOTFOUND', ['one', 'two'])` - returns `['one', 'two']`
    3. `Env::getArray('NOTFOUND', 'one,two,three')` - throws `TypeError` exception
    4. `Env::getArray('ARRAY0')` - returns `['']`
    5. `Env::getArray('ARRAY1')` - returns `['one']`
    6. `Env::getArray('ARRAY')` - returns `['one', 'two', '', 'three']`
- **requireArray** - `public static function requireArray($varname)`

    1. `Env::requireArray('NOTFOUND')` - throws `EnvVarNotFoundException`
    2. `Env::requireArray('EMPTY')` - throws `EnvVarNotFoundException`
    3. `Env::requireArray('ARRAY1')` - returns `['one']`
    4. `Env::requireArray('ARRAY')` - returns `['one', 'two', '', 'three']`

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance77

Regular maintenance activity

Popularity31

Limited adoption so far

Community30

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~106 days

Total

14

Last Release

244d ago

Major Versions

0.2.0 → 1.0.02017-04-12

1.0.1 → 2.0.12017-05-22

2.1.1 → 3.0.02022-02-23

3.4.0 → 4.0.02025-07-09

PHP version history (5 changes)0.1.1PHP &gt;=5.3.3

1.0.1PHP &gt;=5.4

3.0.0PHP ^7.4

3.1.0PHP ^7.4 || ^8.0

4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5e188393958c4505bb06d9e79ed99a47d1cd42551142f02ef364d8268449ef8?d=identicon)[fillup](/maintainers/fillup)

![](https://www.gravatar.com/avatar/836739aa4f60c754dc9a4a547ebd0c166e4b6e855d9f119df2be5aec92f3a375?d=identicon)[forevermatt](/maintainers/forevermatt)

![](https://www.gravatar.com/avatar/a0d56d7e6fc794910b03eff96448007ee05879ad38493f0b5f215c4fe61f4b30?d=identicon)[mtompset](/maintainers/mtompset)

![](https://www.gravatar.com/avatar/5256eacae3564eb6d3e954abc6552ed99a6d948d94d2b07cc1dc9dabb0bce108?d=identicon)[jason-jackson](/maintainers/jason-jackson)

---

Top Contributors

[![forevermatt](https://avatars.githubusercontent.com/u/6233204?v=4)](https://github.com/forevermatt "forevermatt (44 commits)")[![mtompset](https://avatars.githubusercontent.com/u/10937901?v=4)](https://github.com/mtompset "mtompset (27 commits)")[![jason-jackson](https://avatars.githubusercontent.com/u/35783387?v=4)](https://github.com/jason-jackson "jason-jackson (17 commits)")[![lvail](https://avatars.githubusercontent.com/u/2112219?v=4)](https://github.com/lvail "lvail (17 commits)")[![briskt](https://avatars.githubusercontent.com/u/3172830?v=4)](https://github.com/briskt "briskt (8 commits)")[![fillup](https://avatars.githubusercontent.com/u/556105?v=4)](https://github.com/fillup "fillup (5 commits)")[![Baggerone](https://avatars.githubusercontent.com/u/8058522?v=4)](https://github.com/Baggerone "Baggerone (2 commits)")[![longrunningprocess](https://avatars.githubusercontent.com/u/4412848?v=4)](https://github.com/longrunningprocess "longrunningprocess (2 commits)")

---

Tags

getenvphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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