Required to be compatible with PDOStatement::fetchAll(int $mode = PDO::FETCH_DEFAULT, mixed ...$args)
P粉308089080
P粉308089080 2023-12-10 23:55:42
0
1
448

Our client has a drupal website, but the host forces all clients to go from PHP 7.4 to PHP version 8, causing a PDO fatal error that prevents the website from loading.

Error received:

Fatal error: Statement 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) /usr/www/users/kdpsipxqzt/core/lib/Drupal/Core/Database/Statement.php At line 168

The 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 to solve this problem?

I've tried multiple ways to troubleshoot and adjust the function to better match PHP's PDOStatement parent function, but with no success!

Comparison with PHP's PDOStatement:

public function fetchAll($how = null, $className = null, $ctorArgs = null)

Did I miss something?

P粉308089080
P粉308089080

reply all(1)
P粉265724930

The return type must be set to array:

public function fetchAll($mode = null, $column_index = null, $constructor_arguments = null) : array { ... }

If you are using PHP8.1, you can bypass this error by adding the comment #[\ReturnTypeWillChange]

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template