Skip to content

Commit

Permalink
Add a fix for a TypeError when $_SESSION['user'] somehow contains a z…
Browse files Browse the repository at this point in the history
…ero.
  • Loading branch information
campbell-m committed Jul 18, 2024
1 parent 63a8e53 commit 5564fad
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions web/lib/MRBS/Session/SessionPhp.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public function updatePage(?string $url): void

public function getCurrentUser() : ?User
{
$result = $_SESSION['user'] ?? null;

// For some unknown reason the integer value 0 is sometimes stored in the session
// variable. It's not clear how this can happen.
if (isset($result) && !(is_object($result) && is_a($result, 'MRBS\User')))
{
trigger_error('$_SESSION["user"] is expected to be a User object, not ' . json_encode($result), E_USER_WARNING);
$result = null;
}

return $_SESSION['user'] ?? parent::getCurrentUser();
}

Expand Down

0 comments on commit 5564fad

Please sign in to comment.