Skip to content

Commit 3c90060

Browse files
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.
1 parent 9573a8e commit 3c90060

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/FakePdoStatementTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function fetch(
339339
$cursor_orientation = \PDO::FETCH_ORI_NEXT,
340340
$cursor_offset = 0
341341
) {
342-
if ($fetch_style === -123 || $fetch_style === \PDO::FETCH_DEFAULT) {
342+
if ($fetch_style === -123 || (defined('PDO::FETCH_DEFAULT') && $fetch_style === \PDO::FETCH_DEFAULT)) {
343343
$fetch_style = $this->fetchMode;
344344
}
345345

@@ -415,7 +415,7 @@ public function fetchColumn($column = 0)
415415
*/
416416
public function universalFetchAll(int $fetch_style = -123, ...$args) : array
417417
{
418-
if ($fetch_style === -123 || $fetch_style === \PDO::FETCH_DEFAULT) {
418+
if ($fetch_style === -123 || (defined('PDO::FETCH_DEFAULT') && $fetch_style === \PDO::FETCH_DEFAULT)) {
419419
$fetch_style = $this->fetchMode;
420420
$fetch_argument = $this->fetchArgument;
421421
$ctor_args = $this->fetchConstructorArgs;

tests/EndToEndTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function testSelectWithDefaultFetchAssoc()
5454

5555
public function testSelectFetchDefault()
5656
{
57+
if (!defined('PDO::FETCH_DEFAULT')) {
58+
$this->markTestSkipped('PHP version does not support PDO::FETCH_DEFAULT');
59+
}
60+
5761
$pdo = self::getConnectionToFullDB();
5862

5963
$query = $pdo->prepare("SELECT id FROM `video_game_characters` WHERE `id` > :id ORDER BY `id` ASC");

0 commit comments

Comments
 (0)