Search by

sirix / sirix-env

sirix777

This package is abandoned and no longer maintained. The author suggests using the sirix/sirix-config package instead.

A helper function to retrieve environment variables with type casting

1.0.0 2026-01-04 18:13 UTC

This package is auto-updated.

Last update: 2026-11-21 23:15:09 UTC


README

Warning

This package is abandoned and no longer maintained. Use sirix/sirix-config instead: it provides the same global env() function with type casting (plus optional explicit casting to int, float, string, bool and array).

composer remove sirix/sirix-env
composer require sirix/sirix-config

In sirix/sirix-config, env() is a global function, so drop use function Sirix\Env\env;. EnvParser::parse() is replaced by the global parseEnvVar().

A helper function to retrieve environment variables with type casting.

Installation

Install this tool using composer.

composer require sirix/sirix-env

Usage

This library provides a global env function that allows you to retrieve environment variables and automatically cast them to their appropriate PHP types.

Basic Usage

use function Sirix\Env\env;

$value = env('MY_VAR');
$defaultValue = env('NON_EXISTENT', 'default');

Type Casting

The env function automatically casts string values to the following types:

Value PHP Type Result
'true', '(true)' boolean true
'false', '(false)' boolean false
'null', '(null)' null null
'empty', '(empty)' string ''
'123', '1.23' integer / float 123 / 1.23
Other values string Original string (trimmed)

Static usage

If you prefer not to use the global function, you can use the EnvParser class directly:

use Sirix\Env\EnvParser;

$value = EnvParser::parse('true'); // true