Skip to content

Commit

Permalink
Make Sure PDO::FETCH_DEFAULT is Defined
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergiosalvatore committed Jul 8, 2024
1 parent 9573a8e commit 3c90060
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/FakePdoStatementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 3c90060

Please sign in to comment.