Skip to content

Commit

Permalink
MySqliDriver::getResource() fixed access to resource being closed pri…
Browse files Browse the repository at this point in the history
…or to the call in PHP 8 (#410)
  • Loading branch information
dakujem authored and dg committed Dec 12, 2021
1 parent 170eaa5 commit 7b3a6e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Dibi/Drivers/MySqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


Expand Down
9 changes: 9 additions & 0 deletions tests/dibi/Connection.connect.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '']);
Expand Down

0 comments on commit 7b3a6e6

Please sign in to comment.