Declaration of OM\Db::query(string $statement) must be compatible with PDO::query

Harry picture Harry · Nov 7, 2020 · Viewed 16.8k times · Source

I just installed PHP 8 and I have this error appears? How do I fix it?

Fatal error: Declaration of OM\Db::query(string $statement) must be compatible with PDO::query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs) in /home/www/includes/OM/Db.php on line 131

My OM/Db.php

public function query(string $statement) =====> line 131
{
  $statement = $this->autoPrefixTables($statement);

  $args = func_get_args();

  if (count($args) > 1) {
    $DbStatement = call_user_func_array(array($this, 'parent::query'), $args);
  } else {
    $DbStatement = parent::query($statement);
  }

  if ($DbStatement !== false) {
    $DbStatement->setQueryCall('query');
    $DbStatement->setPDO($this);
  }

  return $DbStatement;
}

Answer

David Raleche picture David Raleche · Mar 5, 2021

#1 - Remove from composer Json the similar line

"doctrine/dbal": "^2.10",

#2 - Run

composer upgrade

#3 - Run

composer update

#4 - Voila ! The error should be fixed !