Documentation

Session extends AbstractSession
in package

Session class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

Table of Contents

Properties

$handler  : SessionHandlerInterface|null
Custom session save handler
$instance  : object|null
Instance of the session
$sessionId  : string|null
Session ID
$sessionName  : string|null
Session Name

Methods

__get()  : mixed
Get method to return the value of the $_SESSION global variable
__isset()  : bool
Return the isset value of the $_SESSION global variable
__set()  : void
Set a property in the session object that is linked to the $_SESSION global variable
__unset()  : void
Unset the $_SESSION global variable
close()  : void
Close the session for writing, releasing the session lock without ending the session
count()  : int
Method to get the count of data in the session
getId()  : string
Return the current the session id
getInstance()  : Session
Determine whether or not an instance of the session object exists already, and instantiate the object if it does not exist.
getIterator()  : ArrayIterator
Method to iterate over the session
getName()  : string
Return the current the session name
jsonSerialize()  : array<string|int, mixed>
Get the session values for JSON serialization
kill()  : void
Destroy the session
offsetExists()  : bool
ArrayAccess offsetExists
offsetGet()  : mixed
ArrayAccess offsetGet
offsetSet()  : void
ArrayAccess offsetSet
offsetUnset()  : void
ArrayAccess offsetUnset
regenerateId()  : void
Regenerate the session id
setHandler()  : void
Set a custom session save handler
setRequestValue()  : Session
Set a request-based value
setTimedValue()  : Session
Set a time-based value
sweep()  : Session
Manually check request-based and time-based values, removing any that have expired or exceeded their hop limit
toArray()  : array<string|int, mixed>
Get the session values as an array
checkExpirationValue()  : void
Check a single time-based value against its expiration, removing it once expired
checkExpirationValues()  : void
Check all time-based values against their expirations
checkRequestValue()  : void
Check a single request-based value against its hop limit, removing it once the limit is exceeded
checkRequestValues()  : void
Check all request-based values against their hop limits
__construct()  : mixed
Constructor
init()  : void
Init the session

Properties

$handler

Custom session save handler

private static SessionHandlerInterface|null $handler = null

$instance

Instance of the session

private static object|null $instance = null

$sessionId

Session ID

private string|null $sessionId = null

$sessionName

Session Name

private string|null $sessionName = null

Methods

__get()

Get method to return the value of the $_SESSION global variable

public __get(string $name) : mixed
Parameters
$name : string

__isset()

Return the isset value of the $_SESSION global variable

public __isset(string $name) : bool
Parameters
$name : string
Return values
bool

__set()

Set a property in the session object that is linked to the $_SESSION global variable

public __set(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed
Tags
throws
Exception

__unset()

Unset the $_SESSION global variable

public __unset(string $name) : void
Parameters
$name : string
Tags
throws
Exception

close()

Close the session for writing, releasing the session lock without ending the session

public close() : void

count()

Method to get the count of data in the session

public count() : int
Return values
int

getId()

Return the current the session id

public getId() : string
Return values
string

getInstance()

Determine whether or not an instance of the session object exists already, and instantiate the object if it does not exist.

public static getInstance([array<string|int, mixed> $options = [] ]) : Session
Parameters
$options : array<string|int, mixed> = []
Return values
Session

getIterator()

Method to iterate over the session

public getIterator() : ArrayIterator
Return values
ArrayIterator

getName()

Return the current the session name

public getName() : string
Return values
string

jsonSerialize()

Get the session values for JSON serialization

public jsonSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

kill()

Destroy the session

public kill() : void

offsetExists()

ArrayAccess offsetExists

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Return values
bool

offsetGet()

ArrayAccess offsetGet

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed

offsetSet()

ArrayAccess offsetSet

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed

offsetUnset()

ArrayAccess offsetUnset

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

regenerateId()

Regenerate the session id

public regenerateId([bool $deleteOldSession = true ]) : void
Parameters
$deleteOldSession : bool = true

setHandler()

Set a custom session save handler

public static setHandler(SessionHandlerInterface $handler) : void

Must be called before the first Session::getInstance() call, and before any other code has called session_start() — a save handler has no effect once a session is already active.

Parameters
$handler : SessionHandlerInterface
Tags
throws
Exception

setRequestValue()

Set a request-based value

public setRequestValue(string $key, mixed $value[, int $hops = 1 ]) : Session
Parameters
$key : string
$value : mixed
$hops : int = 1
Return values
Session

setTimedValue()

Set a time-based value

public setTimedValue(string $key, mixed $value[, int $expire = 300 ]) : Session
Parameters
$key : string
$value : mixed
$expire : int = 300
Return values
Session

sweep()

Manually check request-based and time-based values, removing any that have expired or exceeded their hop limit

public sweep() : Session
Return values
Session

toArray()

Get the session values as an array

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

checkExpirationValue()

Check a single time-based value against its expiration, removing it once expired

protected checkExpirationValue(string $key, array<string|int, mixed> &$data, array<string|int, mixed> &$bookkeeping) : void
Parameters
$key : string
$data : array<string|int, mixed>
$bookkeeping : array<string|int, mixed>

checkExpirationValues()

Check all time-based values against their expirations

protected checkExpirationValues(array<string|int, mixed> &$data, array<string|int, mixed> &$bookkeeping) : void
Parameters
$data : array<string|int, mixed>
$bookkeeping : array<string|int, mixed>

checkRequestValue()

Check a single request-based value against its hop limit, removing it once the limit is exceeded

protected checkRequestValue(string $key, array<string|int, mixed> &$data, array<string|int, mixed> &$bookkeeping) : void
Parameters
$key : string
$data : array<string|int, mixed>
$bookkeeping : array<string|int, mixed>

checkRequestValues()

Check all request-based values against their hop limits

protected checkRequestValues(array<string|int, mixed> &$data, array<string|int, mixed> &$bookkeeping) : void
Parameters
$data : array<string|int, mixed>
$bookkeeping : array<string|int, mixed>

__construct()

Constructor

private __construct([array<string|int, mixed> $options = [] ]) : mixed
Parameters
$options : array<string|int, mixed> = []

Private method to instantiate the session object

init()

Init the session

private init() : void

        
On this page

Search results