22
22
*/
23
23
abstract class AbstractSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
24
24
{
25
- private $ sessionName ;
26
- private $ prefetchId ;
27
- private $ prefetchData ;
28
- private $ newSessionId ;
29
- private $ igbinaryEmptyData ;
25
+ private string $ sessionName ;
26
+ private string $ prefetchId ;
27
+ private string $ prefetchData ;
28
+ private ? string $ newSessionId = null ;
29
+ private string $ igbinaryEmptyData ;
30
30
31
31
public function open (string $ savePath , string $ sessionName ): bool
32
32
{
@@ -54,10 +54,10 @@ public function validateId(string $sessionId): bool
54
54
55
55
public function read (string $ sessionId ): string
56
56
{
57
- if (null !== $ this ->prefetchId ) {
57
+ if (isset ( $ this ->prefetchId ) ) {
58
58
$ prefetchId = $ this ->prefetchId ;
59
59
$ prefetchData = $ this ->prefetchData ;
60
- $ this ->prefetchId = $ this ->prefetchData = null ;
60
+ unset( $ this ->prefetchId , $ this ->prefetchData ) ;
61
61
62
62
if ($ prefetchId === $ sessionId || '' === $ prefetchData ) {
63
63
$ this ->newSessionId = '' === $ prefetchData ? $ sessionId : null ;
@@ -74,10 +74,8 @@ public function read(string $sessionId): string
74
74
75
75
public function write (string $ sessionId , string $ data ): bool
76
76
{
77
- if (null === $ this ->igbinaryEmptyData ) {
78
- // see https://github.com/igbinary/igbinary/issues/146
79
- $ this ->igbinaryEmptyData = \function_exists ('igbinary_serialize ' ) ? igbinary_serialize ([]) : '' ;
80
- }
77
+ // see https://github.com/igbinary/igbinary/issues/146
78
+ $ this ->igbinaryEmptyData ??= \function_exists ('igbinary_serialize ' ) ? igbinary_serialize ([]) : '' ;
81
79
if ('' === $ data || $ this ->igbinaryEmptyData === $ data ) {
82
80
return $ this ->destroy ($ sessionId );
83
81
}
@@ -89,7 +87,7 @@ public function write(string $sessionId, string $data): bool
89
87
public function destroy (string $ sessionId ): bool
90
88
{
91
89
if (!headers_sent () && filter_var (ini_get ('session.use_cookies ' ), \FILTER_VALIDATE_BOOLEAN )) {
92
- if (!$ this ->sessionName ) {
90
+ if (!isset ( $ this ->sessionName ) ) {
93
91
throw new \LogicException (sprintf ('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?. ' , static ::class));
94
92
}
95
93
$ cookie = SessionUtils::popSessionCookie ($ this ->sessionName , $ sessionId );
0 commit comments