Skip to content

Commit

Permalink
Session: session_start() return false on error since PHP 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 17, 2021
1 parent b184c45 commit 999f548
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/Http/Session.php
Expand Up @@ -103,21 +103,10 @@ public function start(): void
session_id($id); // causes resend of a cookie to make sure it has the right parameters
}

try {
// session_start returns false on failure only sometimes
Nette\Utils\Callback::invokeSafe(
'session_start',
[['read_and_close' => $this->readAndClose]],
function (string $message) use (&$e): void {
$e = new Nette\InvalidStateException($message);
}
);
} catch (\Throwable $e) {
}

if ($e) {
@session_write_close(); // this is needed
throw $e;
if (!@session_start(['read_and_close' => $this->readAndClose])) { // @ is escalated to exception
$message = Nette\Utils\Helpers::getLastError();
@session_write_close(); // this is needed?
throw new Nette\InvalidStateException($message);
}

$this->initialize();
Expand Down

0 comments on commit 999f548

Please sign in to comment.