PHPackages                             ghostwriter/environment - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ghostwriter/environment

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ghostwriter/environment
=======================

Provides Environment Variables derived from `$\_ENV` and `$\_SERVER` super-globals

2.0.0(3y ago)0322.3kBSD-3-ClausePHPPHP &gt;=8.1 &lt;8.3CI failing

Since Jul 8Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ghostwriter/environment)[ Packagist](https://packagist.org/packages/ghostwriter/environment)[ Docs](https://github.com/ghostwriter/environment)[ GitHub Sponsors](https://github.com/sponsors/ghostwriter)[ RSS](/packages/ghostwriter-environment/feed)WikiDiscussions 2.0.x Synced 1w ago

READMEChangelog (8)Dependencies (1)Versions (29)Used By (0)

Environment
===========

[](#environment)

[![GitHub Sponsors](https://camo.githubusercontent.com/e97230423d35c583f0bc49b6c18cd7f8ee1fc62c834974e0ee2ef28d1fb2593e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f67686f73747772697465723f6c6162656c3d53706f6e736f722b4067686f73747772697465722f656e7669726f6e6d656e74266c6f676f3d4769744875622b53706f6e736f7273)](https://github.com/sponsors/ghostwriter)[![Automation](https://github.com/ghostwriter/environment/actions/workflows/automation.yml/badge.svg)](https://github.com/ghostwriter/environment/actions/workflows/automation.yml)[![Supported PHP Version](https://camo.githubusercontent.com/2a7a705002ab523c094d5d3fc69c8ed11d9271e8f58e58bd9ce97a7b176cc94e/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f67686f73747772697465722f656e7669726f6e6d656e743f636f6c6f723d383839326266)](https://www.php.net/supported-versions)[![Downloads](https://camo.githubusercontent.com/7f7215a0013305f6430b99ab80151b690be5f7f01c54a3b0fd600780a5df2a1d/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f64742f67686f73747772697465722f656e7669726f6e6d656e743f636f6c6f723d626c7565)](https://packagist.org/packages/ghostwriter/environment)

Provides Environment Variables derived from `$_ENV` and `$_SERVER` super-globals

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

[](#installation)

You can install the package via composer:

```
composer require ghostwriter/environment
```

Usage
-----

[](#usage)

```
$environment = new \Ghostwriter\Environment\Environment();

$environment->has('APP_ENV'); // false
$environment->get('APP_ENV', 'dev'); // dev
$environment->get('APP_ENV'); // throws NotFoundException
$environment->set('APP_ENV', 'production');
$environment->has('APP_ENV'); // true
$environment->get('APP_ENV'); // production
$environment->unset('APP_ENV');

$environment->set('APP_KEY', 'secrete');
$environment->has('APP_KEY'); // true
$environment->get('APP_KEY'); // secrete
$environment->unset('APP_KEY');
$environment->has('APP_KEY'); // false
$environment->get('APP_KEY', 'fallback-value'); // fallback-value
$environment->get('APP_KEY'); // throws NotFoundException
```

API
---

[](#api)

```
interface Variables extends Countable, IteratorAggregate
{
    public function count(): int;
    public function get(string $name, string|null $default = null): string;
    /**
     * @return Generator
     */
    public function getIterator(): Generator;
    public function has(string $name): bool;
    public function set(string $name, string $value): void;
    /**
     * @return non-empty-array
     */
    public function toArray(): array;
    public function unset(string $name): void;
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](./CHANGELOG.md) for more information what has changed recently.

Security
--------

[](#security)

If you discover any security related issues, please email `nathanael.esayeas@protonmail.com` instead of using the issue tracker.

Sponsors
--------

[](#sponsors)

\[[`Become a GitHub Sponsor`](https://github.com/sponsors/ghostwriter)\]

Credits
-------

[](#credits)

- [Nathanael Esayeas](https://github.com/ghostwriter)
- [All Contributors](https://github.com/ghostwriter/environment/contributors)

License
-------

[](#license)

The BSD-3-Clause. Please see [License File](./LICENSE) for more information.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance60

Regular maintenance activity

Popularity25

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~87 days

Recently: every ~302 days

Total

17

Last Release

8d ago

Major Versions

0.4.x-dev → 1.0.02022-12-02

1.1.x-dev → 2.0.02023-05-08

2.1.x-dev → 3.0.x-dev2026-05-09

PHP version history (5 changes)0.1.0PHP &gt;=8.0,&lt;8.2

1.0.0PHP &gt;=8.0,&lt;8.3

1.1.0PHP &gt;=8.1,&lt;8.3

2.0.0PHP &gt;=8.1 &lt;8.3

2.0.x-devPHP ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1dbb0131801cc451dad9917ab29aa823b25d7eebc9f3875a9d481d109bdb44ee?d=identicon)[ghostwriter](/maintainers/ghostwriter)

---

Top Contributors

[![ghostwriter](https://avatars.githubusercontent.com/u/9754361?v=4)](https://github.com/ghostwriter "ghostwriter (1179 commits)")

---

Tags

environmentenvironment-variablesghostwriterphpserver-variablesenvironmentghostwriterenvironment variablesserver-variables

### Embed Badge

![Health badge](/badges/ghostwriter-environment/health.svg)

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

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[symfony/dotenv

Registers environment variables from a .env file

3.8k226.7M2.3k](/packages/symfony-dotenv)[foroco/php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing

1554.7M7](/packages/foroco-php-browser-detection)[wolfcast/browser-detection

The Wolfcast BrowserDetection PHP class facilitates the identification of the user's environment such as Web browser, version, platform family, platform version or if it's a mobile device or not.

1391.0M7](/packages/wolfcast-browser-detection)[imliam/laravel-env-set-command

Set a .env file variable from the command line

118352.4k10](/packages/imliam-laravel-env-set-command)[silverstripe/environmentcheck

Provides an API for building environment tests

35503.8k13](/packages/silverstripe-environmentcheck)

PHPackages © 2026

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