Skip to content

Commit 7b3a6e6

Browse files
dakujemdg
authored andcommitted
MySqliDriver::getResource() fixed access to resource being closed prior to the call in PHP 8 (#410)
1 parent 170eaa5 commit 7b3a6e6

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/Dibi/Drivers/MySqliDriver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ public function rollback(?string $savepoint = null): void
253253
*/
254254
public function getResource(): ?\mysqli
255255
{
256-
return @$this->connection->thread_id ? $this->connection : null;
256+
try {
257+
return @$this->connection->thread_id ? $this->connection : null;
258+
} catch (\Throwable $e) {
259+
return null;
260+
}
257261
}
258262

259263

tests/dibi/Connection.connect.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ test('', function () use ($config) {
6363
});
6464

6565

66+
test('', function () use ($config) {
67+
$conn = new Connection($config);
68+
Assert::true($conn->isConnected());
69+
70+
$conn->__destruct();
71+
Assert::false($conn->isConnected());
72+
});
73+
74+
6675
test('', function () use ($config) {
6776
Assert::exception(function () use ($config) {
6877
new Connection($config + ['onConnect' => '']);

0 commit comments

Comments
 (0)