sirix/sirix-env

A helper function to retrieve environment variables with type casting

Fund package maintenance!
sirix777
buymeacoffee.com/sirix

Installs: 24

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/sirix/sirix-env

1.0.0 2026-01-04 18:13 UTC

This package is auto-updated.

Last update: 2026-01-04 18:15:33 UTC


README

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