PHPackages                             session-interop/utils.arraysession - 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. session-interop/utils.arraysession

ActiveLibrary

session-interop/utils.arraysession
==================================

This package contains the session interface implementation

3.0.0(9y ago)053.7k23MITPHPPHP &gt;=7.1.0

Since Dec 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/session-interop/utils.session)[ Packagist](https://packagist.org/packages/session-interop/utils.arraysession)[ Docs](https://github.com/session-interop/utils.session)[ RSS](/packages/session-interop-utilsarraysession/feed)WikiDiscussions 3.0 Synced 2mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (3)

[![Build Status](https://camo.githubusercontent.com/c784d80a40525cefcf950e461d71aafd032358ae18b575d6196d3733732a5cfd/68747470733a2f2f7472617669732d63692e6f72672f73657373696f6e2d696e7465726f702f7574696c732e73657373696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/session-interop/utils.session)[![Coverage Status](https://camo.githubusercontent.com/932fb1fbcfe329aaa668f0c53353be60290da8853197b3480d39b11adedf60bf/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f73657373696f6e2d696e7465726f702f7574696c732e73657373696f6e2f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/session-interop/utils.session?branch=master)

Array Session
=============

[](#array-session)

This package is a basic implementation of [`SessionInterface`](https://github.com/session-interop/session-interop)

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

[](#installation)

You can install this package through Composer:

```
composer require session-interop/utils.arraysession
```

The packages adheres to the [SemVer](http://semver.org/) specification, and there will be full backward compatibility between minor versions.

Available
---------

[](#available)

### [`SessionArray`](src/ArraySession.php).

[](#sessionarray)

The implementation of SessionInterface.

#### Methods

[](#methods)

###### `__construct(&$array, $prefix = "")`

[](#__constructarray-prefix--)

Construct the object. The object will use $array to store element. It use a reference on $array, so $array will be modified when you use `set($key)`and `remove($key)`. If prefix is given, it will automatically prefix all `$key`.

###### `has($key)`

[](#haskey)

Verify is the key `$key` exists into the array injected at the object construction. Throw an exception if the `key` is not a string. if the associated value is `null`, the method return `true`.

###### `get($key)`

[](#getkey)

Get the value associated with `$key`. Throw an exception if no key are found or if the key is not a string

###### `set($key, $val)`

[](#setkey-val)

Set the value `$val` at the key `$key`. Throw an exception if the key is not a string.

###### `remove($key)`

[](#removekey)

Destroy the element at `$key`

### [`SessionException`](src/Exception/SessionException.php).

[](#sessionexception)

Exception used on error. Throw an exception if the key is not a string

Usage
-----

[](#usage)

Writing an user service that use the session interface:

UserService.php

```
namespace Usage;
use Interop\Session\SessionInterface;
class UserService {
      public function isConnected(SessionInterface $session) {
          if ($session->has("userId")) {
	     	   return true;
	        }
	       return false;
      }
      public function login(SessionInterface $session, $userId) {
        if ($this->isConnected($session)) {
          return false;
  	    }
  	    $session->set("userId", $userId);
  	    return true;
      }
      public function logoff(SessionInterface $session) {
        if ($this->isConnected($session)) {
	     	     $session->remove("userId");
		           return true;
	       }
	      return false;
      }
}
```

Use the implementation:

Index.php

```
use Interop\Session\Utils\ArraySession\ArraySession;
use Usage\UserService;
require_once("vendor/autoload.php");

session_start();

$userId = 1;
$userService = new UserService();
$session = new ArraySession($_SESSION, "myprefix");

// Check if the user is connected

if ($userService->isConnected($session)) {
  // logoff the user
  $userService->logoff($session);
}
else {
  // login the user
  $userService->login($session, $userId);
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~1 days

Total

6

Last Release

3427d ago

Major Versions

1.0.x-dev → 2.0.02016-12-23

2.0.x-dev → 3.0.02016-12-29

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=7.1.0

### Community

Maintainers

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

---

Top Contributors

[![Ngob](https://avatars.githubusercontent.com/u/2749238?v=4)](https://github.com/Ngob "Ngob (24 commits)")[![xhuberty](https://avatars.githubusercontent.com/u/8350192?v=4)](https://github.com/xhuberty "xhuberty (1 commits)")

---

Tags

phpsessionphp sessionsessioninterface

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/session-interop-utilsarraysession/health.svg)

```
[![Health](https://phpackages.com/badges/session-interop-utilsarraysession/health.svg)](https://phpackages.com/packages/session-interop-utilsarraysession)
```

PHPackages © 2026

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