Our client has a drupal website, but the host has forced all clients from PHP 7.4 to PHP version 8, causing a PDO fatal error preventing the site from loading.
Error Received:
Fatal error: Declaration of
DrupalCoreDatabaseStatement::fetchAll(int $mode =
PDO::FETCH_DEFAULT, $column_index = null, $constructor_arguments =
null) must be compatible with PDOStatement::fetchAll(int $mode =
PDO::FETCH_DEFAULT, mixed …$args) in
/usr/www/users/kdpsipxqzt/core/lib/Drupal/Core/Database/Statement.php
on line 168
Function causing the problem:
ERROR (L 168) ->
public function fetchAll($mode = null, $column_index = NULL, $constructor_arguments = NULL) {
// Call PDOStatement::fetchAll to fetch all rows.
// PDOStatement is picky about the number of arguments in some cases so we
// need to be pass the exact number of arguments we where given.
switch (func_num_args()) {
case 0:
return parent::fetchAll();
case 1:
return parent::fetchAll($mode);
case 2:
return parent::fetchAll($mode, $column_index);
case 3:
default:
return parent::fetchAll($mode, $column_index, $constructor_arguments);
}
}
Does anyone have any ideas on resolving this?
I’ve tried troubleshooting in a number of ways, adjusting the function to better match the PDOStatement parent function of PHP but with no luck!
Comparing against PHP’s PDOStatement:
public function fetchAll($how = null, $className = null, $ctorArgs = null)
Am I missing something?
2
Answers
The return type must be set to
array
:If you’re using PHP8.1 you can bypass the error by adding the comment
#[ReturnTypeWillChange]
As i noted in my comment above, i would not change the drupal method manually.
But here you can see, how it can be made.