PHPackages                             vboivin/superglobals - 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. vboivin/superglobals

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

vboivin/superglobals
====================

Type-safe access to php superglobals

v2.0.0(3y ago)12MITHack

Since Sep 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Vboivin/Superglobals)[ Packagist](https://packagist.org/packages/vboivin/superglobals)[ Docs](https://github.com/vboivin/Superglobals)[ RSS](/packages/vboivin-superglobals/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (5)Used By (0)

Superglobals
============

[](#superglobals)

[![CI](https://github.com/vboivin/Superglobals/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/vboivin/Superglobals/actions/workflows/build_and_test.yml)

Type-safe access to php superglobals.

Components
==========

[](#components)

Server
------

[](#server)

Class representing the $\_SERVER superglobal.

Example of accessing 'REQUEST\_METHOD' on $\_SERVER:

```
use type Superglobals\Server;

$server = new Server();
$server->$REQUEST_METHOD; // 'GET', 'HEAD', 'POST', 'PUT', etc. or null
```

Example of using the raw $\_SERVER superglobal:

```
use type Superglobals\Server;

$unsafeServer = Server::_UNSAFE();
$unsafeServer['REQUEST_METHOD']; // 'GET', 'HEAD', 'PUT', etc. or null
$unsafeServer['UNKNOWN_VARIABLE']; // Could be anything
```

Get
---

[](#get)

Class representing the $\_GET superglobal.

Example of using $\_GET with a user defined query string:

```
use type Superglobals\{Get, QueryString, QueryVariable};

final class PersonQuery {
     public ?int $age;
     public ?string $name;
}

$query = new Get(PersonQuery::class);
$query?->data?->age; // Do something with the person's age
$query?->data?->name; // Do something with the person's name
```

Post
----

[](#post)

Class representing the $\_POST superglobal.

Example of using $\_POST with a user defined form:

```
use type Superglobals\{Form, FormVariable, Post};

final class SignupForm {
     public ?int $age;
     public ?string $name;
     public ?string $email;
}

$form = new Post(SignupForm::class);
$form?->data?->age; // Do something with the person's age
$form?->data?->name; // Do something with the person's name
$form?->data?->email; // Do something with the person's email
```

Cookies
-------

[](#cookies)

Class representing the $\_COOKIE superglobal.

Example of using $\_COOKIE with user defined cookies:

```
use type Superglobals\{Cookie, Cookies, CookiesData};

final class MyCookies {
     public ?string $foo;
     public ?int $bar;
     public ?float $baz;
}

$cookies = new Cookies(MyCookies::class);
$fooCookie = $cookies?->data?->foo; // Do something with the data within cookie 'foo'
$barCookie = $cookies?->data?->bar; // Do something with the data within cookie 'bar'
$bazCookie = $cookies?->data?->baz; // Do something with the data within cookie 'baz'
```

Session
-------

[](#session)

Class representing the $\_SESSION superglobal.

Example of using $\_SESSION with user defined properties:

```
use type Superglobals\{Session, SessionData, SessionVariable};

final class MySession {
     public ?string $savedID;
     public ?string $lastPageSeen;
}

$session = new Session(MySession::class);
$session?->data?->savedID; // Do something with the session's saved ID
$session?->data?->lastPageSeen; // Do something with the session's last seen page
```

SuperglobalException
--------------------

[](#superglobalexception)

This exception is thrown when you are not using a class attribute on the class being instantiated by one of the superglobals class defined in this library.

Here is an example using $\_POST:

```
use type Superglobals\{Form, FormVariable, Post};

// INVALID CODE
final class InvalidSignupForm {
     public ?string $name;
}
$invalidForm = new Post(InvalidSignupForm::class); // An exception will be thrown here

// VALID CODE

final class ValidSignupForm {
     public ?string $name;
}
$validForm = new Post(ValidSignupForm::class); // No exception thrown here
```

Contributing
============

[](#contributing)

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

1. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
2. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
3. Push to the Branch (`git push origin feature/AmazingFeature`)
4. Open a Pull Request

License
=======

[](#license)

Superglobals is MIT-licensed.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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 ~0 days

Total

4

Last Release

1388d ago

Major Versions

v1.2.0 → v2.0.02022-09-14

### Community

Maintainers

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

---

Tags

hhvmhacktype-safesuperglobals

### Embed Badge

![Health badge](/badges/vboivin-superglobals/health.svg)

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

PHPackages © 2026

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