PHPackages                             darlanschmeller/php-env-loader - 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. darlanschmeller/php-env-loader

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

darlanschmeller/php-env-loader
==============================

Lightweight .env file loader for PHP with automatic type casting

v2.0.2(3mo ago)134MITPHPPHP &gt;=8.0CI passing

Since Jan 15Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/DarlanSchmeller/php-env-loader)[ Packagist](https://packagist.org/packages/darlanschmeller/php-env-loader)[ RSS](/packages/darlanschmeller-php-env-loader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

🪴 PHP Env Loader ![.env](https://camo.githubusercontent.com/879432bbb7b03f6738d3d45dc4f6708e8d40d289848fa831c0834e92f0333d45/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2e656e762d4c6f616465722d2532333030433835333f6c6f676f3d656e7669726f6e6d656e74266c6f676f436f6c6f723d7768697465267374796c653d666f722d7468652d6261646765)
===========================================================================================================================================================================================================================================================================================================================================================

[](#-php-env-loader-)

[![PHP](https://camo.githubusercontent.com/0fab92c36bf4f5ecf36a89b9e0406349c55f9c76baef96272873e5cd5e72333a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e302d626c75653f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/) [![Packagist](https://camo.githubusercontent.com/5646486a86680215542e66cc1f81d6f74f8bcab3729c40b71549a4222b424688/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6461726c616e7363686d656c6c65722f7068702d656e762d6c6f61646572)](https://packagist.org/packages/darlanschmeller/php-env-loader) [![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE) [![PHP Composer CI](https://github.com/DarlanSchmeller/php-env-loader/actions/workflows/php.yml/badge.svg)](https://github.com/DarlanSchmeller/php-env-loader/actions/workflows/php.yml/badge.svg)

A lightweight, object-oriented PHP library to load `.env` files into `$_ENV` with **automatic type casting** and **quote handling**. Perfect for small projects, scripts, or when you want a simple alternative to `vlucas/phpdotenv`.

Features
--------

[](#features)

- Load `.env` files into `$_ENV` automatically
- Supports `export` keyword
- Inline comment handling (`# comment`)
- Quote string handling (`"string"` or `'string'`)
- Automatic type casting:
    - `"true"` / `"false"` → `bool`
    - Numeric strings → `int` or `float`
    - `"null"` → `null`
- Static helper method for convenience
- Comprehensive PHPUnit test coverage

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

[](#installation)

### Via Composer (recommended)

[](#via-composer-recommended)

```
composer require darlanschmeller/php-env-loader
```

Include in your project:

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

use DarlanSchmeller\EnvLoader\EnvLoader;
```

### From source (for development only)

[](#from-source-for-development-only)

```
git clone https://github.com/DarlanSchmeller/php-env-loader.git
```

Include in your project:

```
require __DIR__ . '/src/EnvLoader.php';

use DarlanSchmeller\EnvLoader\EnvLoader;
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
$env = new EnvLoader(); // Defaults to '../.env'
$variables = $env->load();

var_dump($variables); // Loaded env variables
var_dump($_ENV);      // Also accessible globally
```

### Static Convenience

[](#static-convenience)

If you just want to load a `.env` without instantiating the class:

```
$variables = EnvLoader::loadFrom(__DIR__ . '/.env');
```

### Sample .env

[](#sample-env)

```
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD="supersecret"
APP_DEBUG=true
TIMEOUT=5.5
```

After loading

```
$_ENV['DB_PORT'];      // int(3306)
$_ENV['DB_PASSWORD'];  // string("supersecret")
$_ENV['APP_DEBUG'];    // bool(true)
$_ENV['TIMEOUT'];      // float(5.5)
```

Note

- Inline comments are supported outside quotes, e.g., `DB_HOST=127.0.0.1 # main database host`
- Quotes around values are stripped automatically
- Empty strings and "null" values are converted to null

Running Automated Tests
-----------------------

[](#running-automated-tests)

Run all PHPUnit tests for this library:

```
./vendor/bin/phpunit tests
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance81

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

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

Total

3

Last Release

103d ago

Major Versions

v1.0.0 → v2.0.02026-01-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ca13f0b14c2f3886054bb63eaa82df6feb2204a7f3388faf52f7e899bd2a010?d=identicon)[DarlanSchmeller](/maintainers/DarlanSchmeller)

---

Top Contributors

[![DarlanSchmeller](https://avatars.githubusercontent.com/u/157293733?v=4)](https://github.com/DarlanSchmeller "DarlanSchmeller (18 commits)")

---

Tags

composerconfigurationdotenvenvenvironment-variablesphpphp-libraryzero-dependencies

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/darlanschmeller-php-env-loader/health.svg)

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

PHPackages © 2026

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