PHPackages                             linuscash/with-global-state - 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. linuscash/with-global-state

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

linuscash/with-global-state
===========================

a simple way to make global state clear in order to bring it back under control

v1.0.0(7y ago)09MITPHP

Since Aug 27Pushed 7y ago1 watchersCompare

[ Source](https://github.com/linuscash/with-global-state)[ Packagist](https://packagist.org/packages/linuscash/with-global-state)[ RSS](/packages/linuscash-with-global-state/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (2)Used By (0)

with-global-state
=================

[](#with-global-state)

withGlobalState is a simple utility that will wrap any function in order to make its global state requirements clear.

motivation
----------

[](#motivation)

Working on an application recently I found that large chunks of it shared global state. I wanted to focus my efforts untangling modules that shared state but didn't want to go all big bang on it and run down the rabbit hole. Thus this little function was born. I used it to get a grip on each modules global state while I refactored it out without interfering with the other modules.

example
-------

[](#example)

```
function greetMe (String $moniker): String
{
    return "Hello {$moniker} my name is {$GLOBALS['name']}";
}

greetMe('stranger'); // ??

$linusGreetMe = withGlobalState('greetMe', ['name' => 'Linus']);
$linusGreetMe('stranger'); // "Hello stranger my name is Linus"
```

The above is a contrived example but it does demonstrate the functions purpose. We can see a poorly implemented function that depends on global state instantly become more readable, manageable and testable.

Essentially we can write tests against this legacy code. Once we have a handle on it, we can refactor it down to something more meanful and maintainable without treading on the toes of other modules.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Unknown

Total

1

Last Release

2864d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6534699?v=4)[Linus Cash](/maintainers/linuscash)[@linuscash](https://github.com/linuscash)

---

Top Contributors

[![linuscash](https://avatars.githubusercontent.com/u/6534699?v=4)](https://github.com/linuscash "linuscash (1 commits)")

---

Tags

global-staterefactoringstate-managementtestability

### Embed Badge

![Health badge](/badges/linuscash-with-global-state/health.svg)

```
[![Health](https://phpackages.com/badges/linuscash-with-global-state/health.svg)](https://phpackages.com/packages/linuscash-with-global-state)
```

###  Alternatives

[laravolt/semantic-form

Semantic UI form helpers

5213.0k4](/packages/laravolt-semantic-form)[phpsgi/phpsgi

373.2k3](/packages/phpsgi-phpsgi)

PHPackages © 2026

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