我們的客戶有一個(gè) drupal 網(wǎng)站,但主機(jī)強(qiáng)制所有客戶端從 PHP 7.4 到 PHP 版本 8,導(dǎo)致 PDO 致命錯(cuò)誤導(dǎo)致網(wǎng)站無法加載。
收到錯(cuò)誤:
致命錯(cuò)誤:聲明 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 行
導(dǎo)致問題的函數(shù):
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); } }
有人有解決這個(gè)問題的想法嗎?
我嘗試了多種方式進(jìn)行故障排除,調(diào)整函數(shù)以更好地匹配 PHP 的 PDOStatement 父函數(shù),但沒有成功!
與 PHP 的 PDOStatement 比較:
public function fetchAll($how = null, $className = null, $ctorArgs = null)
我錯(cuò)過了什么嗎?
返回類型必須設(shè)置為數(shù)組
:
public function fetchAll($mode = null, $column_index = null, $constructor_arguments = null) : array { ... }
如果您使用的是 PHP8.1,您可以通過添加注釋 #[\ReturnTypeWillChange]
來繞過該錯(cuò)誤