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

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

datahihi1/tiny-env
==================

A simple environment variable loader for PHP applications

1.1.1(1mo ago)24732MITPHPPHP &gt;=8.0CI passing

Since Feb 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/datahihi1/tiny-env)[ Packagist](https://packagist.org/packages/datahihi1/tiny-env)[ RSS](/packages/datahihi1-tiny-env/feed)WikiDiscussions main Synced today

READMEChangelog (10)DependenciesVersions (23)Used By (2)Security (2)

TinyEnv
=======

[](#tinyenv)

A lightweight .env loader for PHP projects.

Fast, Safe, Simple — designed for small to medium projects.

### Installation

[](#installation)

```
composer require datahihi1/tiny-env:1.1.1
```

### Quick Start

[](#quick-start)

```
require 'vendor/autoload.php';

use Datahihi1\TinyEnv\TinyEnv;

$env = new TinyEnv(__DIR__);
$env->load();

echo env('DB_HOST', 'localhost');
```

.env file:

```
DB_HOST=127.0.0.1
DB_PORT=3306
```

### Features

[](#features)

#### 1. load() – Standard load

[](#1-load--standard-load)

```
$env->load();                           // Load all
$env->load(specificKeys: ['DB_HOST']);  // Load specific keys
$env->load([], forceReload: true);      // Force reload (overwrite existing values)
$env->load([], noFile: true);           // Load without requiring .env file to exist
```

#### 2. Fast load

[](#2-fast-load)

```
$env = new TinyEnv(__DIR__, true); // Load immediately and populate $_SERVER|$_ENV but only .env and not recommended for production
```

#### 3. Multiple .env files

[](#3-multiple-env-files)

```
$env->envfiles(['.env', '.env.production', '.env.local']); // Load in order, pre-declaration file has the highest priority by default (.env > .env.production > .env.local)
$env->envfiles(['.env.production', '.env.local'], prioritizeEnv: true); // Prioritize .env file by loading it first, allows overwriting other files
```

#### Allow specific stream wrappers (advanced)

[](#allow-specific-stream-wrappers-advanced)

By default, TinyEnv rejects some values that look like dangerous PHP stream wrappers (e.g. `phar:`, `php://`, `data:`) to reduce the chance that an env value is later used unsafely by your app.

If you *intentionally* need to use a wrapper such as `phar://...`, you can opt-in with an allowlist:

```
$env = new TinyEnv(__DIR__);
$env->allowWrapperSchemes(['phar']); // opt-in to allow phar://... values
$env->load();
```

#### Populate Superglobals

[](#populate-superglobals)

```
$env = new TinyEnv(__DIR__); // By default, superglobals are NOT populated to avoid unintended side effects. You can enable it explicitly:
$env->populateSuperglobals(); // Enable superglobals population
$env->populateServerglobals(); // Enable server globals population
$env->load();
```

Or use `fastLoad` which will always populate superglobals - **But not recommended for production**.

- Getting Values

```
echo env('NAME');                // Get value
echo env('NOT_FOUND', 'backup'); // With default
print_r(env());                  // Get all (in .env file)
print_r(sysenv());               // Get all system variables
```

- Validation

Using [tiny-env-validator](https://github.com/datahihi1/tiny-env-validator.git)

- Encryption

Using [tiny-env-encryptor](https://github.com/datahihi1/tiny-env-encryptor.git)

### Variable Interpolation

[](#variable-interpolation)

TinyEnv supports shell-style interpolation inside .env values:

```
DB_HOST=localhost
DB_PORT=3306
DB_URL=${DB_HOST}:${DB_PORT}

USER_NAME=
USER=${USER_NAME:-guest}   # default if unset or empty
ALT_USER=${USER_NAME-guest} # default if unset only
REQUIRED=${MISSING?Missing variable MISSING}
```

Result:

```
DB_URL="localhost:3306"

USER="guest" (because USER_NAME is empty)

ALT_USER="" (because USER_NAME exists but empty)

REQUIRED → throws Exception
```

**Notes**

> - Comments start with `#`.
> - Variable names: `A-Z`, `0-9`, `_`.
> - Spaces around `=` still valid but not recommended.
> - Values are auto-parsed into correct types:
>     - `"true", "yes", "on"` → `true`
>     - `"false", "no", "off"` → `false`
>     - `"123"` → `int`
>     - `"12.3"` → `float` or `double`
>     - `"null"` or empty → `null`
> - TinyEnv considers yes/no, on/off to be boolean values.
> - Use `"/value/"` to force string type.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance93

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Recently: every ~13 days

Total

21

Last Release

36d ago

PHP version history (3 changes)1.0.1PHP &gt;=7.0

1.0.4PHP &gt;=7.1

1.1.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/148314027?v=4)[Dat Duy](/maintainers/datahihi1)[@datahihi1](https://github.com/datahihi1)

---

Top Contributors

[![datahihi1](https://avatars.githubusercontent.com/u/148314027?v=4)](https://github.com/datahihi1 "datahihi1 (46 commits)")

### Embed Badge

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

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

###  Alternatives

[stuttter/wp-multi-network

Provides a Network Management Interface for global administrators in WordPress Multisite installations.

23624.7k1](/packages/stuttter-wp-multi-network)[gedcomx/gedcomx-php

PHP libraries for GEDCOM X.

359.3k2](/packages/gedcomx-gedcomx-php)[retinens/laravel-cookie-consent

Make your Laravel app comply with the crazy EU cookie law

354.6k](/packages/retinens-laravel-cookie-consent)

PHPackages © 2026

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