From 3c90060ed91cce439ef1ceac44196f82f89754de Mon Sep 17 00:00:00 2001 From: Sergio Salvatore Date: Mon, 8 Jul 2024 09:58:57 -0400 Subject: [PATCH] Make Sure PDO::FETCH_DEFAULT is Defined PDO::FETCH_DEFAULT arrived as of PHP v8.0.7. For those still on 7.4 referring to it directly in the code causes it to break with an undefined constant. This checks to make sure the constant exists before comparing against it. --- src/FakePdoStatementTrait.php | 4 ++-- tests/EndToEndTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FakePdoStatementTrait.php b/src/FakePdoStatementTrait.php index 06603c89..ce33ca36 100644 --- a/src/FakePdoStatementTrait.php +++ b/src/FakePdoStatementTrait.php @@ -339,7 +339,7 @@ public function fetch( $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset = 0 ) { - if ($fetch_style === -123 || $fetch_style === \PDO::FETCH_DEFAULT) { + if ($fetch_style === -123 || (defined('PDO::FETCH_DEFAULT') && $fetch_style === \PDO::FETCH_DEFAULT)) { $fetch_style = $this->fetchMode; } @@ -415,7 +415,7 @@ public function fetchColumn($column = 0) */ public function universalFetchAll(int $fetch_style = -123, ...$args) : array { - if ($fetch_style === -123 || $fetch_style === \PDO::FETCH_DEFAULT) { + if ($fetch_style === -123 || (defined('PDO::FETCH_DEFAULT') && $fetch_style === \PDO::FETCH_DEFAULT)) { $fetch_style = $this->fetchMode; $fetch_argument = $this->fetchArgument; $ctor_args = $this->fetchConstructorArgs; diff --git a/tests/EndToEndTest.php b/tests/EndToEndTest.php index e2790b56..b3ccc72e 100644 --- a/tests/EndToEndTest.php +++ b/tests/EndToEndTest.php @@ -54,6 +54,10 @@ public function testSelectWithDefaultFetchAssoc() public function testSelectFetchDefault() { + if (!defined('PDO::FETCH_DEFAULT')) { + $this->markTestSkipped('PHP version does not support PDO::FETCH_DEFAULT'); + } + $pdo = self::getConnectionToFullDB(); $query = $pdo->prepare("SELECT id FROM `video_game_characters` WHERE `id` > :id ORDER BY `id` ASC");