From 999f54884deed7a419b13552271c7059a5acb428 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 5 Sep 2021 23:59:09 +0200 Subject: [PATCH] Session: session_start() return false on error since PHP 7.1 --- src/Http/Session.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Http/Session.php b/src/Http/Session.php index da975e30..fe6e7fb7 100644 --- a/src/Http/Session.php +++ b/src/Http/Session.php @@ -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();