From 7b3a6e6c72fc0b60921c24e8dc0b081b9a890d97 Mon Sep 17 00:00:00 2001 From: Andrej Rypo Date: Sun, 12 Dec 2021 03:54:42 +0100 Subject: [PATCH] MySqliDriver::getResource() fixed access to resource being closed prior to the call in PHP 8 (#410) --- src/Dibi/Drivers/MySqliDriver.php | 6 +++++- tests/dibi/Connection.connect.phpt | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySqliDriver.php index 45bc275fa..e2bb8f2f0 100644 --- a/src/Dibi/Drivers/MySqliDriver.php +++ b/src/Dibi/Drivers/MySqliDriver.php @@ -253,7 +253,11 @@ public function rollback(?string $savepoint = null): void */ public function getResource(): ?\mysqli { - return @$this->connection->thread_id ? $this->connection : null; + try { + return @$this->connection->thread_id ? $this->connection : null; + } catch (\Throwable $e) { + return null; + } } diff --git a/tests/dibi/Connection.connect.phpt b/tests/dibi/Connection.connect.phpt index fbc7501a1..bfcc4e7aa 100644 --- a/tests/dibi/Connection.connect.phpt +++ b/tests/dibi/Connection.connect.phpt @@ -63,6 +63,15 @@ test('', function () use ($config) { }); +test('', function () use ($config) { + $conn = new Connection($config); + Assert::true($conn->isConnected()); + + $conn->__destruct(); + Assert::false($conn->isConnected()); +}); + + test('', function () use ($config) { Assert::exception(function () use ($config) { new Connection($config + ['onConnect' => '']);