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

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

oscarotero/env
==============

Simple library to consume environment variables

v2.1.1(1y ago)9411.4M—3.3%6[1 issues](https://github.com/oscarotero/env/issues)20MITPHPPHP &gt;=7.1

Since Dec 30Pushed 1y ago2 watchersCompare

[ Source](https://github.com/oscarotero/env)[ Packagist](https://packagist.org/packages/oscarotero/env)[ Docs](https://github.com/oscarotero/env)[ RSS](/packages/oscarotero-env/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (10)Used By (20)

env
===

[](#env)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/51cb69714ad63c26418460b8e2aaefded5c08a8e4ed781ec427ffd191b00f1eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f736361726f7465726f2f656e762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oscarotero/env)

Simple library to get environment variables converted to simple types.

Installation
------------

[](#installation)

This package is installable and autoloadable via Composer as [oscarotero/env](https://packagist.org/packages/oscarotero/env).

```
composer require oscarotero/env
```

Example
-------

[](#example)

```
use Env\Env;

// Using getenv function:
var_dump(getenv('FOO')); //string(5) "false"

// Using Env:
var_dump(Env::get('FOO')); //bool(false)
```

Available conversions
---------------------

[](#available-conversions)

- `"false"` is converted to boolean `false`
- `"true"` is converted to boolean `true`
- `"null"` is converted to `null`
- If the string contains only numbers is converted to an integer
- If the string has quotes, remove them

Options
-------

[](#options)

To configure the conversion, you can use the following constants (all enabled by default):

- `Env::CONVERT_BOOL` To convert boolean values
- `Env::CONVERT_NULL` To convert null values
- `Env::CONVERT_INT` To convert integer values
- `Env::STRIP_QUOTES` To remove the quotes of the strings

There's also additional settings that you can enable (they're disabled by default)

- `Env::USE_ENV_ARRAY` To get the values from `$_ENV`, instead `getenv()`.
- `Env::USE_SERVER_ARRAY` To get the values from `$_SERVER`, instead `getenv()`.
- `Env::LOCAL_FIRST` To get first the values of locally-set environment variables.

```
use Env\Env;

//Convert booleans and null, but not integers or strip quotes
Env::$options = Env::CONVERT_BOOL | Env::CONVERT_NULL;

//Add one more option
Env::$options |= Env::USE_ENV_ARRAY;

//Remove one option
Env::$options ^= Env::CONVERT_NULL;
```

Default value
-------------

[](#default-value)

By default, if the value does not exist, returns `null`, but you can change for any other value:

```
use Env\Env;

Env::$default = false;
```

The env() function
------------------

[](#the-env-function)

You can use the `env()` function, like in Laravel or other frameworks:

```
use function Env\env;

var_dump(env('FOO'));
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity59

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 92% 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 ~407 days

Recently: every ~517 days

Total

9

Last Release

532d ago

Major Versions

v1.x-dev → v2.0.02020-06-03

PHP version history (2 changes)v1.0.0PHP &gt;=5.2

v2.0.0PHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (46 commits)")[![onnimonni](https://avatars.githubusercontent.com/u/5691777?v=4)](https://github.com/onnimonni "onnimonni (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![tangrufus](https://avatars.githubusercontent.com/u/2259834?v=4)](https://github.com/tangrufus "tangrufus (1 commits)")[![tristanmarsh](https://avatars.githubusercontent.com/u/3328024?v=4)](https://github.com/tristanmarsh "tristanmarsh (1 commits)")

---

Tags

envenvironment-variablesenv

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/oscarotero-env/health.svg)](https://phpackages.com/packages/oscarotero-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)[helhum/dotenv-connector

Makes it possible to set environment variables for composer projects.

1594.6M34](/packages/helhum-dotenv-connector)[ffraenz/private-composer-installer

A composer install helper for private packages

2331.7M5](/packages/ffraenz-private-composer-installer)[m1/env

Env is a lightweight library bringing .env file parser compatibility to PHP. In short - it enables you to read .env files with PHP.

6412.0M21](/packages/m1-env)[sroze/companienv

Companion for .env files

245418.8k1](/packages/sroze-companienv)

PHPackages © 2026

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