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

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

flavioheleno/env
================

Handle environment variables like a breeze.

v0.3(5y ago)2118[3 PRs](https://github.com/flavioheleno/env/pulls)mitPHPPHP &gt;=7.3

Since Nov 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/flavioheleno/env)[ Packagist](https://packagist.org/packages/flavioheleno/env)[ Docs](https://github.com/flavioheleno/env)[ RSS](/packages/flavioheleno-env/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (3)Dependencies (7)Versions (7)Used By (0)

env [![Maintainability](https://camo.githubusercontent.com/f0318f172b12162a525b75ee74a4d72eac12f4b5fa18d34a086f005eb8882d85/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f37616438316237376530356134636439636239372f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/flavioheleno/env/maintainability) [![Total Downloads](https://camo.githubusercontent.com/8129a4495cec5cddd38b09d9f3ef181e8f188bc1e21f643c00eb8c7951295689/68747470733a2f2f706f7365722e707567782e6f72672f666c6176696f68656c656e6f2f656e762f646f776e6c6f616473)](//packagist.org/packages/flavioheleno/env)
===========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#env--)

Handle environment variables like a breeze.

Install with composer
---------------------

[](#install-with-composer)

```
composer require flavioheleno/env
```

Read or Required?
-----------------

[](#read-or-required)

This library comes with two helpers:

- `Env\Read`, which will try to read a variable and return its value or fallback to the `$default` value when the variable isn't set;
- `Env\Required`, which will try to read a variable and return its value or throw an exception when the variable isn't set.

Usage
-----

[](#usage)

You can **read** environment variables with:

```
$value = Env\Read::asString('my_var', 'default_value');
```

On the other hand, you can **require** environment variables with:

```
try {
  $value = Env\Required::asString('my_var');
} catch (RuntimeException $exception) {
  // handle exception
}
```

Immutable environment
---------------------

[](#immutable-environment)

The library loads the environment variables into a internal copy on the first method call.

If you ever need to update the internal copy, you can do that with:

```
Env\Read::updateEnv();
```

or:

```
Env\Required::updateEnv();
```

Available methods
-----------------

[](#available-methods)

All methods below are available in both the `Env\Read` and `Env\Required` helpers.

- **updateEnv**: Updates the internal env var copy;
- **asString**:: Returns the value as a string;
- **asArray**: Returns the values as an array (comma separated);
- **asInteger**: Returns the value as an integer;
- **asFloat**: Returns the value as a float;
- **asBool**: Returns the value as a boolean;
- **fromJson**: Returns the value as a json decoded value/object;
- **fromSerialized**: Returns the value as a unserialized value/object.

Contributing
------------

[](#contributing)

There are a few helper scripts that can be called by composer, such as:

- Static Code Analysis: `php composer.phar run check`
- Code Linting: `php composer.phar run lint`
- Tests: `php composer.phar run test`

**NOTE:** to run the *Code Linting*, you must download the ruleset from [here](https://github.com/flavioheleno/phpcs-ruleset/blob/master/ruleset.xml) first.

License
-------

[](#license)

This library is licensed under the [MIT License](LICENSE).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.9% 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 ~211 days

Total

3

Last Release

1954d ago

PHP version history (3 changes)v0.1PHP &gt;=7.2

v0.2PHP ^7.3

v0.3PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/42b9c9cbc06973a61587667fc811b853f4d71843f35ba2535f3900083e69ab3f?d=identicon)[flavioheleno](/maintainers/flavioheleno)

---

Top Contributors

[![flavioheleno](https://avatars.githubusercontent.com/u/471860?v=4)](https://github.com/flavioheleno "flavioheleno (28 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")

---

Tags

envenv-varsenvironmentenvironment-variableshacktoberfestvariablesenvironmentenvenvironment-variableenv varenvvarenv variable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k226.7M2.3k](/packages/symfony-dotenv)[imliam/laravel-env-set-command

Set a .env file variable from the command line

118352.4k10](/packages/imliam-laravel-env-set-command)[msztorc/laravel-env

Laravel env helper commands

7855.4k](/packages/msztorc-laravel-env)[cekurte/environment

A library to get the values from environment variables and process to php data types

5884.0k7](/packages/cekurte-environment)[mirazmac/dotenvwriter

A PHP library to write values to .env (DotEnv) files

19129.3k7](/packages/mirazmac-dotenvwriter)

PHPackages © 2026

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