Skip to content

Commit 5b119c8

Browse files
author
Jonathon Hill
committed
Fix several TypeErrors when accessing unset properties
1 parent 80da31c commit 5b119c8

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

src/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setSavePath(string $save_path): self
2323

2424
public function getSavePath(): ?string
2525
{
26-
return $this->save_path;
26+
return $this->save_path ?? null;
2727
}
2828

2929
protected SessionHandlerInterface $save_handler;
@@ -36,7 +36,7 @@ public function setSaveHandler(SessionHandlerInterface $save_handler): self
3636

3737
public function getSaveHandler(): ?SessionHandlerInterface
3838
{
39-
return $this->save_handler;
39+
return $this->save_handler ?? null;
4040
}
4141

4242
protected SerializerInterface $serialize_handler;

src/Handlers/RedisHandler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ public function __construct(Config $config)
3131

3232
public function open($path, $name): bool
3333
{
34-
if ($this->redis) {
34+
if (isset($this->redis)) {
3535
return false;
3636
}
3737

38-
$this->redis = null;
39-
$this->store = null;
40-
4138
// Parse redis connection settings from save path
4239
$query = [];
4340
$config = parse_url($path);
@@ -69,12 +66,12 @@ public function close(): bool
6966
{
7067
$this->store = null;
7168

72-
if (!$this->redis) {
69+
if (!isset($this->redis)) {
7370
return false;
7471
}
7572

7673
$success = $this->redis->close();
77-
$this->redis = null;
74+
unset($this->redis);
7875

7976
return $success;
8077
}

src/Manager.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public function getConfig(): Config
3838
*/
3939
public function getCurrentSession(): ?Session
4040
{
41-
return $this->currentSession;
41+
return $this->currentSession ?? null;
4242
}
4343

4444
/**
4545
* Discard session array changes and finish session
4646
*/
4747
public function abort(): bool
4848
{
49-
if (!$this->currentSession) {
49+
if (!isset($this->currentSession)) {
5050
return false;
5151
}
5252

@@ -59,7 +59,7 @@ public function abort(): bool
5959
*/
6060
public function commit(): bool
6161
{
62-
if (!$this->currentSession) {
62+
if (!isset($this->currentSession)) {
6363
return false;
6464
}
6565

@@ -160,7 +160,7 @@ public function gc()
160160
*/
161161
public function id(string $id = null): string
162162
{
163-
$returnId = $this->currentSession
163+
$returnId = isset($this->currentSession)
164164
? $this->currentSession->getId()
165165
: "";
166166

@@ -238,7 +238,7 @@ public function register_shutdown(): void
238238
*/
239239
public function reset(): bool
240240
{
241-
if (!$this->currentSession) {
241+
if (!isset($this->currentSession)) {
242242
return false;
243243
}
244244

@@ -324,7 +324,7 @@ public function start(): bool
324324
}
325325

326326
if (
327-
!$this->currentSession
327+
!isset($this->currentSession)
328328
|| (
329329
$handler instanceof SessionUpdateTimestampHandlerInterface
330330
&& !$handler->validateId($this->currentSession->getId())
@@ -391,7 +391,7 @@ public function status(): int
391391
return \PHP_SESSION_DISABLED;
392392
}
393393

394-
if (!$this->currentSession || !$this->currentSession->isInitialized()) {
394+
if (!isset($this->currentSession) || !$this->currentSession->isInitialized()) {
395395
return \PHP_SESSION_NONE;
396396
}
397397

@@ -403,7 +403,7 @@ public function status(): int
403403
*/
404404
public function unset(): bool
405405
{
406-
if (!$this->currentSession) {
406+
if (!isset($this->currentSession)) {
407407
return false;
408408
}
409409

@@ -420,7 +420,7 @@ public function unset(): bool
420420
*/
421421
public function write_close(): bool
422422
{
423-
if (!$this->currentSession) {
423+
if (!isset($this->currentSession)) {
424424
return false;
425425
}
426426

0 commit comments

Comments
 (0)