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

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

phpexperts/env
==============

Use Laravel's pre-5.8 env() function in your non-Laravel projects.

v1.7.0(1y ago)562MITPHPPHP &gt;=7.0CI failing

Since May 9Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (9)Versions (11)Used By (0)

Laravel 5.7 env() Polyfill
==========================

[](#laravel-57-env-polyfill)

[![TravisCI](https://camo.githubusercontent.com/b935db3ff19b8b6b7f8ae8f20887959e72353e1c012d17b144ec476c9eb47abe/68747470733a2f2f7472617669732d63692e6f72672f70687065787065727473696e632f4c61726176656c35372d656e762d706f6c7966696c6c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpexpertsinc/Laravel57-env-polyfill)[![Test Coverage](https://camo.githubusercontent.com/553298123e1b2fa20e67755cda1186baf0852e82cc6c4ac7e01e0f0218bb35a1/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f34303535373539613239306362633739376635662f746573745f636f766572616765)](https://codeclimate.com/github/phpexpertsinc/Laravel57-env-polyfill/test_coverage)

Benefits
--------

[](#benefits)

- Works with *any* package, even non-Laravel ones (it was my secondary reason)
- You no longer have to fear Laravel just going one day "Oops! We're not going to read from the environment anymore! Too bad!" on a non-major release.

Backstory
---------

[](#backstory)

With the introduction of Laravel 5.8, they broke the essential `env()` function by changing it from reading from/writing to environment variables to only using the global `$_SERVER` array, which is totally useless in console-based apps.

See

- [laravel/framework#27462](https://github.com/laravel/framework/pull/27462)
- [laravel/framework#27828](https://github.com/laravel/framework/issues/27828)
- [laravel/framework#27949](https://github.com/laravel/framework/issues/27949)

Therefore, I took it upon myself to create this polyfill to ensure that the pre-5.8 behaviors remain intact.

Additionally, this is a great little utility function to use outside of Laravel-specic projects that also want to use the `env()` function.

It is specially configured with a `0.0.1` composer vendor and a `AAutoloadFirst`namespace, so that composer will always load it before it gets to Laravel. See [composer/composer#6768](https://github.com/composer/composer/issues/6768)

The source code is lifted directly from the last version of Laravel 5.7.

As you can imagine, most of the copyright in this project belongs to Taylor Otwell, 2018.

It also includes 100% unit test code .

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

[](#installation)

Via Composer

```
composer require phpexperts/laravel-env-polyfill
```

Usage
-----

[](#usage)

```
putenv('foo=bar');
$foo = \env('foo'); // 'bar'
```

and

```
if (in_array(SomeTrait::class, class_uses_recursive($this)) {
    // The class or its child it's being called from uses SomeTrait.
}
```

Use cases
=========

[](#use-cases)

PHPExperts\\Laravel57EnvPolyfill\\Tests\\Env
✔ Env
✔ Env with quotes
✔ Env true
✔ Env false
✔ Env empty
✔ Env null
✔ Value
✔ Env will use default value if needed
✔ Will load vlucas/phpdot if a .env is present.
✔ Will not load vlucas/phpdotenv if a .env is not present.

Testing
-------

[](#testing)

```
phpunit
```

Contributors
============

[](#contributors)

[Theodore R. Smith](https://www.phpexperts.pro/%5D)
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.

[Taylor Otwell](https://www.laravel.com/)

License
-------

[](#license)

MIT license. Please see the [license file](LICENSE) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

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

Recently: every ~357 days

Total

10

Last Release

643d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f3a2dd16766f6b03c330e65aaca9dfb97f1bbbb41c5e2af5681f58f670b7917?d=identicon)[hopeseekr](/maintainers/hopeseekr)

---

Top Contributors

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

---

Tags

shimlaravelenv5.7

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[msztorc/laravel-env

Laravel env helper commands

7855.4k](/packages/msztorc-laravel-env)[allysonsilva/laravel-multienv

This package allows you to use multiple .envs in multitenant environment

537.2k](/packages/allysonsilva-laravel-multienv)[harmonic/laravel-envcoder

:description

414.1k](/packages/harmonic-laravel-envcoder)

PHPackages © 2026

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