PHPackages                             phpgt/protectedglobal - 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. [Security](/categories/security)
4. /
5. phpgt/protectedglobal

ActiveLibrary[Security](/categories/security)

phpgt/protectedglobal
=====================

Protect against accidental use of superglobals.

v2.0.0(8mo ago)03.4k↓37.3%1[3 PRs](https://github.com/PhpGt/ProtectedGlobal/pulls)2MITPHPPHP &gt;=8.2CI passing

Since Jan 14Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/PhpGt/ProtectedGlobal)[ Packagist](https://packagist.org/packages/phpgt/protectedglobal)[ RSS](/packages/phpgt-protectedglobal/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (2)Versions (17)Used By (2)

Protect against accidental use of superglobals.
===============================================

[](#protect-against-accidental-use-of-superglobals)

By default, PHP passes all sensitive user information around in superglobal variables, available for reading and modification in any code, including third party libraries. This directly violates a lot of the benefits of Object Oriented Programming, and can lead to unmaintainable code.

Assuming there are object oriented abstractions to the superglobals set up, this library can be used to replace all superglobals with objects that alert the developer of their protection and encapsulation, with an optional whitelist of superglobals to keep.

---

[ ![Build status](https://camo.githubusercontent.com/187da2926a9384756e2383135616aaf76e6ecd49224425422349d0b2faa1ad88/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f746563746564676c6f62616c2d6275696c642e737667)](https://github.com/PhpGt/ProtectedGlobal/actions)[ ![Code quality](https://camo.githubusercontent.com/3b01c892a9b22d136b617574ac373236d7e7d4ea542d0bbbd525ad6950dfbd77/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f746563746564676c6f62616c2d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/ProtectedGlobal)[ ![Code coverage](https://camo.githubusercontent.com/fefd0a79c28ae703e2d78773fb1e12914598c716062f531f138dfc9a16670b0d/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f746563746564676c6f62616c2d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/ProtectedGlobal)[ ![Current version](https://camo.githubusercontent.com/7e25fdd755c5bfd4fba14f070e6e5dbcbcae96ee61e10ce956be907060dd1579/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f746563746564676c6f62616c2d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/ProtectedGlobal)[ ![PHP.Gt/ProtectedGlobal documentation](https://camo.githubusercontent.com/7ee78fc00617914942f130ac7a65000ec369a251ae48dd62f9fe0076d0acfa71/68747470733a2f2f62616467652e7374617475732e7068702e67742f70726f746563746564676c6f62616c2d646f63732e737667)](http://www.php.gt/protectedglobal)There are two functions on the static `Protection` class:

1. `removeGlobals` - pass in an array containing the global arrays you wish to empty. Take an optional whitelist of keys to keep.
2. `overrideInternals` - pass in all superglobal arrays to override with the `ProtectedGlobal` class.

Example usage:
--------------

[](#example-usage)

```
// Before protecting, abstract the globals using an OOP mechanism of choice.
$input = new Input($_GET, $_POST, $_FILES);
// etc...

Protection::removeGlobals([$_ENV, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION], ["get" => ["xdebug"]]);
Protection::overrideInternals($_GLOBALS, $_ENV, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION);

// Now an exception will be thrown when trying to access a global variable:
$_SESSION["god-object"] = "Value I want to pass around globally";
```

Proudly sponsored by
====================

[](#proudly-sponsored-by)

[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://www.jetbrains.com/community/opensource/)

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance75

Regular maintenance activity

Popularity22

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 51.7% 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 ~405 days

Recently: every ~583 days

Total

8

Last Release

252d ago

Major Versions

v0.2.0 → v1.0.02019-06-03

v1.1.2 → v2.0.02025-10-23

PHP version history (3 changes)v0.1.0PHP &gt;7.1

v1.1.0PHP &gt;7.4

v2.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

[![dependabot-support](https://avatars.githubusercontent.com/u/112581971?v=4)](https://github.com/dependabot-support "dependabot-support (15 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (10 commits)")[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (3 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

global-variablesno-aiobject-orientedphp-oopphp-securityphpgtsecurity

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgt-protectedglobal/health.svg)

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

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.7M143](/packages/mews-purifier)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24820.0k37](/packages/paragonie-ecc)

PHPackages © 2026

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