要求与PDOStatement::fetchAll(int $mode = PDO::FETCH_DEFAULT, mixed ...$args)兼容
P粉308089080
P粉308089080 2023-12-10 23:55:42
0
1
409

我们的客户有一个 drupal 网站,但主机强制所有客户端从 PHP 7.4 到 PHP 版本 8,导致 PDO 致命错误导致网站无法加载。

收到错误:

致命错误:声明 DrupalCoreDatabaseStatement::fetchAll(int $mode = PDO::FETCH_DEFAULT,$column_index = null,$constructor_arguments = null) 必须与 PDOStatement::fetchAll(int $mode = 兼容 PDO::FETCH_DEFAULT,混合...$args) /usr/www/users/kdpsipxqzt/core/lib/Drupal/Core/Database/Statement.php 在第 168 行

导致问题的函数:

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);
    }
  }

有人有解决这个问题的想法吗?

我尝试了多种方式进行故障排除,调整函数以更好地匹配 PHP 的 PDOStatement 父函数,但没有成功!

与 PHP 的 PDOStatement 比较:

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

我错过了什么吗?

P粉308089080
P粉308089080

全部回复(1)
P粉265724930

返回类型必须设置为数组

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

如果您使用的是 PHP8.1,您可以通过添加注释 #[\ReturnTypeWillChange] 来绕过该错误

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!