PHPackages                             zadorin/better-getenv - 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. zadorin/better-getenv

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

zadorin/better-getenv
=====================

Simple helper to retrieve environment variables

v0.0.1(4y ago)05MITPHPPHP &gt;=7.4

Since Jan 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/eugenezadorin/better-getenv)[ Packagist](https://packagist.org/packages/zadorin/better-getenv)[ RSS](/packages/zadorin-better-getenv/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Better getenv()
===============

[](#better-getenv)

Package provides framework-agnostic helper `env($key, $default)` to retrieve environment variables in convenient way.

Highly inspired by [Laravel env helper](https://laravel.com/docs/8.x/helpers#method-env).

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

[](#installation)

```
composer require zadorin/better-getenv

```

Usage
-----

[](#usage)

```
$varName = 'APP_ENV';
$defaultValue = 'prod';

$value = env($varName, $defaultValue);
```

Second parameter can be a function. In that case helper will use result of this function as default value:

```
$value = env('CACHE_STORAGE', function () {
    return env('APP_ENV', 'prod') === 'prod' ? 'redis' : 'file';
});
```

Usage Notes
-----------

[](#usage-notes)

Helper will search variable in `$_ENV` first, using `getenv()` as fallback.

If `env()` function already exists in your codebase, you can use namespaced call with same signature:

```
$value = Zadorin\env('APP_ENV', 'prod');
```

Helper automatically casts string values `'true', 'false'` to boolean type. Similarly, `'null'` string casts to null.

Tests
-----

[](#tests)

```
./vendor/bin/pest

```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

1632d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7566566?v=4)[Eugene Zadorin](/maintainers/eugenezadorin)[@eugenezadorin](https://github.com/eugenezadorin)

---

Tags

environmentenvgetenv

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/zadorin-better-getenv/health.svg)

```
[![Health](https://phpackages.com/badges/zadorin-better-getenv/health.svg)](https://phpackages.com/packages/zadorin-better-getenv)
```

###  Alternatives

[vlucas/phpdotenv

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

13.5k627.3M6.1k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k237.6M2.6k](/packages/symfony-dotenv)[imliam/laravel-env-set-command

Set a .env file variable from the command line

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

Laravel env helper commands

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

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

5886.2k8](/packages/cekurte-environment)[mirazmac/dotenvwriter

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

21142.7k11](/packages/mirazmac-dotenvwriter)

PHPackages © 2026

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