PHPackages                             tiny-blocks/environment-variable - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. tiny-blocks/environment-variable

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

tiny-blocks/environment-variable
================================

Provides a simple and flexible solution for managing environment variables, with easy access, type conversions, and validation handling.

1.2.0(4mo ago)11.2k↓25.9%1MITPHPPHP ^8.5CI passing

Since Dec 9Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/tiny-blocks/environment-variable)[ Packagist](https://packagist.org/packages/tiny-blocks/environment-variable)[ Docs](https://github.com/tiny-blocks/environment-variable)[ RSS](/packages/tiny-blocks-environment-variable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (1)

Environment variable
====================

[](#environment-variable)

[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

- [Overview](#overview)
- [Installation](#installation)
- [How to use](#how-to-use)
- [License](#license)
- [Contributing](#contributing)

Overview
--------

[](#overview)

Provides a simple and flexible solution for managing environment variables, with easy access, type conversions, and validation handling.

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

[](#installation)

```
composer require tiny-blocks/environment-variable
```

How to use
----------

[](#how-to-use)

### Creating an environment variable

[](#creating-an-environment-variable)

To create and work with environment variables, use the `from` method to get an instance of the environment variable.

```
EnvironmentVariable::from(name: 'MY_VAR');
```

To retrieve an environment variable with the option of providing a default value in case the variable does not exist, use the `fromOrDefault` method.

If the environment variable is not found, the method will return the provided default value instead of throwing an exception.

```
EnvironmentVariable::fromOrDefault(name: 'MY_VAR', defaultValueIfNotFound: 'default_value');
```

### Conversions

[](#conversions)

Once you have an instance of the environment variable, you can convert its value into various types.

#### Convert to string

[](#convert-to-string)

To convert the environment variable to a string.

```
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toString();
```

#### Convert to integer

[](#convert-to-integer)

To convert the environment variable to an integer.

```
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toInteger();
```

#### Convert to boolean

[](#convert-to-boolean)

To convert the environment variable to a boolean.

```
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toBoolean();
```

### Check if the environment variable has a value

[](#check-if-the-environment-variable-has-a-value)

Checks if the environment variable has a value. Values like `false`, `0`, and `-1` are valid and non-empty.

```
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->hasValue();
```

License
-------

[](#license)

Environment variable is licensed under [MIT](LICENSE).

Contributing
------------

[](#contributing)

Please follow the [contributing guidelines](https://github.com/tiny-blocks/tiny-blocks/blob/main/CONTRIBUTING.md) to contribute to the project.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance81

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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 ~134 days

Total

4

Last Release

123d ago

PHP version history (2 changes)1.0.0PHP ^8.3

1.2.0PHP ^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/b00a83241d2af272255f1755bf6aff48e77821c59ef623520176d9e828977241?d=identicon)[gustavofreze](/maintainers/gustavofreze)

---

Top Contributors

[![gustavofreze](https://avatars.githubusercontent.com/u/22873481?v=4)](https://github.com/gustavofreze "gustavofreze (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

envenvironmentenvironment-variableshacktoberfestopen-sourcephptiny-blockspsrenvtiny-blocksenvironment-variable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tiny-blocks-environment-variable/health.svg)

```
[![Health](https://phpackages.com/badges/tiny-blocks-environment-variable/health.svg)](https://phpackages.com/packages/tiny-blocks-environment-variable)
```

###  Alternatives

[psr/container

Common Container Interface (PHP FIG PSR-11)

10.0k1.0B3.7k](/packages/psr-container)[psr/clock

Common interface for reading the clock.

642332.9M343](/packages/psr-clock)[lctrs/psalm-psr-container-plugin

Let Psalm understand better psr11 containers

17648.1k13](/packages/lctrs-psalm-psr-container-plugin)[mayflower/mo4-coding-standard

PHP CodeSniffer ruleset implementing the MO4 coding standards extending the Symfony coding standards.

17508.3k5](/packages/mayflower-mo4-coding-standard)

PHPackages © 2026

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