Lightweight .env loader for PHP projects

v2.0.0 2025-09-28 06:50 UTC

This package is auto-updated.

Last update: 2025-09-28 06:51:38 UTC


README

Latest Version on Packagist Total Downloads License Tests

A simple and lightweight .env loader for PHP projects.

๐Ÿ“ฆ Installation

Via Composer:

composer require codemonster-ru/env

๐Ÿš€ Usage

Create a .env file in the root of your project:

APP_NAME=MyApp
FEATURE_ENABLED=true
FEATURE_DISABLED=false
OPTIONAL_VALUE=null
EMPTY_VALUE=empty
SSR_URL="http://localhost:3000"

Load .env in your app:

<?php

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

use Codemonster\Env\Env;

Env::load(__DIR__ . '/.env');

echo env('APP_NAME'); // "MyApp"
var_dump(env('FEATURE_ENABLED')); // true (bool)
var_dump(env('FEATURE_DISABLED')); // false (bool)
var_dump(env('OPTIONAL_VALUE')); // null
var_dump(env('EMPTY_VALUE')); // ""
echo env('SSR_URL'); // http://localhost:3000
echo env('NOT_DEFINED', 'default'); // "default"

โœจ Features

  • Loading .env files into $_ENV, $_SERVER, and via putenv().
  • Boolean value support:
  • true, (true) โ†’ true
  • false, (false) โ†’ false
  • Support for null and empty:
  • null, (null) โ†’ null
  • empty, (empty) โ†’ ""
  • Support for quoted strings "..." and '...'.
  • Global function env($key, $default = null).

๐Ÿงช Testing

You can run tests with the command:

composer test

๐Ÿ‘จโ€๐Ÿ’ป Author

Kirill Kolesnikov

๐Ÿ“œ License

MIT