Installation with Composer
composer require polymorphine/session
In procedural code you would have to call session_start()
to allow access to superglobal $_SESSION
array.
This library also requires initialisation phase, but it is achieved with (PSR-15) middleware.
Request going through this middleware will trigger SessionContext
,
and SessionStorage
will become available.
The session storage is not superglobal anymore, and it can be passed explicitly into objects that require access to its data. The downside is that it cannot be instantiated directly before request processing is started, so lazy initialisation is necessary one way or another.