From 9608903db7fcfadb3974564b614a411c8f5aa374 Mon Sep 17 00:00:00 2001 From: Michal Kruczek Date: Wed, 7 Dec 2022 13:41:25 +0100 Subject: [PATCH 1/2] keep BC for sqlite adapter when php >=8.1 https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite --- library/Zend/Db/Adapter/Pdo/Sqlite.php | 8 ++++++++ tests/Zend/Db/Adapter/Pdo/SqliteTest.php | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/library/Zend/Db/Adapter/Pdo/Sqlite.php b/library/Zend/Db/Adapter/Pdo/Sqlite.php index 5b71b99eed..86a8601a7f 100644 --- a/library/Zend/Db/Adapter/Pdo/Sqlite.php +++ b/library/Zend/Db/Adapter/Pdo/Sqlite.php @@ -91,6 +91,14 @@ public function __construct(array $config = []) $this->_config['username'] = null; $this->_config['password'] = null; + if (PHP_VERSION_ID >= 80100) { + // ensure $config['driver_options'] is an array + $config['driver_options'] = empty($config['driver_options']) ? array() : $config['driver_options']; + if (!isset($config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES])) { + $config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES] = true; + } + } + return parent::__construct($config); } diff --git a/tests/Zend/Db/Adapter/Pdo/SqliteTest.php b/tests/Zend/Db/Adapter/Pdo/SqliteTest.php index 3df6b87c1d..7ab0af2792 100644 --- a/tests/Zend/Db/Adapter/Pdo/SqliteTest.php +++ b/tests/Zend/Db/Adapter/Pdo/SqliteTest.php @@ -261,4 +261,26 @@ public function testAdapterQuoteNullByteCharacter() $value = $this->_db->quote($string); $this->assertEquals("'1\\000'", $value); } + + /** + * https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite + * @inheritDoc + */ + public function testAdapterZendConfigEmptyDriverOptions() + { + $params = $this->_util->getParams(); + $params['driver_options'] = ''; + $params = new Zend_Config($params); + + $db = Zend_Db::factory($this->getDriver(), $params); + $db->getConnection(); + + $config = $db->getConfig(); + + if (PHP_VERSION_ID >= 80100) { + $this->assertEquals(array(PDO::ATTR_STRINGIFY_FETCHES => true), $config['driver_options']); + } else { + $this->assertEquals(array(), $config['driver_options']); + } + } } From e5fc4eae08d291ab811b590d6a2214f5b625e8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C6=B0ng=20Tr=E1=BB=8Bnh?= Date: Mon, 6 Feb 2023 14:54:30 +0700 Subject: [PATCH 2/2] Use short array and coalesce language features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elan Ruusamäe --- library/Zend/Db/Adapter/Pdo/Sqlite.php | 2 +- tests/Zend/Db/Adapter/Pdo/SqliteTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/Zend/Db/Adapter/Pdo/Sqlite.php b/library/Zend/Db/Adapter/Pdo/Sqlite.php index 86a8601a7f..5babd670a6 100644 --- a/library/Zend/Db/Adapter/Pdo/Sqlite.php +++ b/library/Zend/Db/Adapter/Pdo/Sqlite.php @@ -93,7 +93,7 @@ public function __construct(array $config = []) if (PHP_VERSION_ID >= 80100) { // ensure $config['driver_options'] is an array - $config['driver_options'] = empty($config['driver_options']) ? array() : $config['driver_options']; + $config['driver_options'] = $config['driver_options'] ?? []; if (!isset($config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES])) { $config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES] = true; } diff --git a/tests/Zend/Db/Adapter/Pdo/SqliteTest.php b/tests/Zend/Db/Adapter/Pdo/SqliteTest.php index 7ab0af2792..06d4784a15 100644 --- a/tests/Zend/Db/Adapter/Pdo/SqliteTest.php +++ b/tests/Zend/Db/Adapter/Pdo/SqliteTest.php @@ -269,7 +269,7 @@ public function testAdapterQuoteNullByteCharacter() public function testAdapterZendConfigEmptyDriverOptions() { $params = $this->_util->getParams(); - $params['driver_options'] = ''; + $params['driver_options'] = []; $params = new Zend_Config($params); $db = Zend_Db::factory($this->getDriver(), $params); @@ -278,9 +278,9 @@ public function testAdapterZendConfigEmptyDriverOptions() $config = $db->getConfig(); if (PHP_VERSION_ID >= 80100) { - $this->assertEquals(array(PDO::ATTR_STRINGIFY_FETCHES => true), $config['driver_options']); + $this->assertEquals([PDO::ATTR_STRINGIFY_FETCHES => true], $config['driver_options']); } else { - $this->assertEquals(array(), $config['driver_options']); + $this->assertEquals([], $config['driver_options']); } } }