diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 9534db33a49..a6604727a8d 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -21,8 +21,6 @@ use function mysqli_error; use function mysqli_init; use function mysqli_options; -use function restore_error_handler; -use function set_error_handler; use function sprintf; use function stripos; @@ -79,15 +77,8 @@ public function __construct(array $params, $username, $password, array $driverOp $this->setSecureConnection($params); $this->setDriverOptions($driverOptions); - set_error_handler(static function (): bool { - return false; - }); - try { - if (! $this->conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { - throw ConnectionFailed::new($this->conn); - } - } finally { - restore_error_handler(); + if (! @$this->conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { + throw ConnectionFailed::new($this->conn); } if (! isset($params['charset'])) { diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index c0953ea532b..d2facb1faaa 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -3,14 +3,10 @@ namespace Doctrine\Tests\DBAL\Driver\Mysqli; use Doctrine\DBAL\Driver\Mysqli\MysqliConnection; -use Doctrine\DBAL\Driver\Mysqli\MysqliException; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\Tests\DbalFunctionalTestCase; use PHPUnit\Framework\MockObject\MockObject; -use function restore_error_handler; -use function set_error_handler; - /** * @requires extension mysqli */ @@ -40,24 +36,4 @@ public function testDoesNotRequireQueryForServerVersion(): void { self::assertFalse($this->connectionMock->requiresQueryForServerVersion()); } - - public function testRestoresErrorHandlerOnException(): void - { - $handler = static function (): bool { - self::fail('Never expected this to be called'); - }; - - $defaultHandler = set_error_handler($handler); - - try { - new MysqliConnection(['host' => '255.255.255.255'], 'user', 'pass'); - self::fail('An exception was supposed to be raised'); - } catch (MysqliException $e) { - self::assertSame('Network is unreachable', $e->getMessage()); - } - - self::assertSame($handler, set_error_handler($defaultHandler), 'Restoring error handler failed.'); - restore_error_handler(); - restore_error_handler(); - } }