A simple library to loads environment variables from “.env” file

1.0.0 2022-02-16 07:17 UTC

This package is auto-updated.

Last update: 2025-04-28 13:04:41 UTC


README

A simple library to loads environment variables from “.env” file.

Installation

Install via Composer:

$ composer require sergeyakovlev/env

Usage

Initialization

use SergeYakovlev\Env\Env;

// If necessary non-default initialization
Env::init('/path/to/project', ['.env.dist', '.env']); // This is the default behavior

Use cases

// The first use case
$dbHostname = Env::var('DB_HOSTNAME');

// The second use case is with the default value
$dbHostname = Env::var('DB_HOSTNAME', 'localhost');

// Check if an environment variable is existed
$dbHostnameIsExists = Env::exists('DB_HOSTNAME');

Example of “.env” file

# Comment Line

STRING_VAR1=StringValueWithoutSpaces
STRING_VAR2="String value with spaces"

BOOLEAN_VAR1=true
BOOLEAN_VAR2=false

BOOLEAN_VAR3=on
BOOLEAN_VAR4=off

INT_VAR=123

FLOAT_VAR=123.45