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.0.16(2mo ago)22982MITPHPPHP &gt;=7.1CI passing

Since Feb 28Pushed 2mo 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 1mo ago

READMEChangelog (10)DependenciesVersions (18)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.0.16
```

### 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);          // Overwrite existing values
$env->load(noFile:true);                // Load but skip checking .env file existence
```

#### 2. Fast load

[](#2-fast-load)

```
$env = new TinyEnv(__DIR__, fastLoad: true); // Fast load with one call, only if .env exists and populate superglobals/serverglobals enabled
# $env->load();                             // No need to call load() again
```

#### 3. Multiple .env files

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

```
$env = new TinyEnv(__DIR__.'/to/path/env');
$env->envfiles(['.env', '.env.local', '.env.production']);
$env->load(); // Load from multiple files but .env is always first
```

TinyEnv always loads `.env` first, then any additional files in the order specified.

#### Populate Superglobals

[](#populate-superglobals)

```
$env = new TinyEnv(__DIR__);
$env->populateSuperglobals();   // Enable superglobals population
$env->populateServerglobals();  // Enable $_SERVER 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

39

—

LowBetter than 86% of packages

Maintenance83

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

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

Recently: every ~35 days

Total

16

Last Release

85d ago

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

1.0.4PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d4e04716bebfe938a06dfd6da1d7c0c51927d8549a2dbcdbd72d23a8c8c5f79?d=identicon)[datahihi1](/maintainers/datahihi1)

---

Top Contributors

[![datahihi1](https://avatars.githubusercontent.com/u/148314027?v=4)](https://github.com/datahihi1 "datahihi1 (43 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

[wablas/wablas-client-php

(Unoficial) Wablas Client PHP

141.4k](/packages/wablas-wablas-client-php)

PHPackages © 2026

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