diff --git a/core/lib/Drupal/Core/Database/Php8StatementTrait.php b/core/lib/Drupal/Core/Database/Php8StatementTrait.php index 7224e545b5..b1b5dbf3c1 100644 --- a/core/lib/Drupal/Core/Database/Php8StatementTrait.php +++ b/core/lib/Drupal/Core/Database/Php8StatementTrait.php @@ -14,8 +14,10 @@ trait Php8StatementTrait { * constants used. * * @param int $mode - * One of the PDO::FETCH_* constants. - * Default to what was specified by setFetchMode(). + * One of the PDO::FETCH_* constants. Defaults to what was specified by + * setFetchMode(). Note the default value on the implementation is different + * from the default value on \PDO::fetch() for PHP 8 in order to allow + * \Drupal\Core\Database\StatementPrefetch to behave the same on PHP 7 & 8. * @param int $cursor_orientation * Not implemented in all database drivers, don't use. * @param int $cursor_offset @@ -24,7 +26,7 @@ trait Php8StatementTrait { * @return * A result, formatted according to $mode. */ - public function fetch(int $mode = \PDO::FETCH_BOTH, int $cursor_orientation = \PDO::FETCH_ORI_NEXT, int $cursor_offset = 0) { + public function fetch(int $mode = 0, int $cursor_orientation = \PDO::FETCH_ORI_NEXT, int $cursor_offset = 0) { return $this->doFetch($mode, $cursor_orientation, $cursor_offset); } diff --git a/core/lib/Drupal/Core/Database/StatementPrefetch.php b/core/lib/Drupal/Core/Database/StatementPrefetch.php index 3c46426772..845f366585 100644 --- a/core/lib/Drupal/Core/Database/StatementPrefetch.php +++ b/core/lib/Drupal/Core/Database/StatementPrefetch.php @@ -396,7 +396,7 @@ public function rowCount() { public function doFetch($mode) { if (isset($this->currentRow)) { // Set the fetch parameter. - $this->fetchStyle = isset($mode) ? $mode : $this->defaultFetchStyle; + $this->fetchStyle = !empty($mode) ? $mode : $this->defaultFetchStyle; $this->fetchOptions = $this->defaultFetchOptions; // Grab the row in the format specified above.