Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible return type of EPDOStatement\EPDOStatement::bindParam #18

Open
yonicsurny opened this issue Oct 30, 2022 · 1 comment
Open

Comments

@yonicsurny
Copy link

Hi,

I'm facing the following issue when using EPDOStatement:

During inheritance of PDOStatement: Uncaught Whoops\Exception\ErrorException: Return type of EPDOStatement\EPDOStatement::bindParam($param, &$value, $datatype = PDO::PARAM_STR, $length = 0, $driverOptions = false) should either be compatible with PDOStatement::bindParam(string|int $param, mixed &$var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/myuser/Documents/Projects/myapp/vendor/noahheck/e_pdostatement/src/EPDOStatement.php:80
Stack trace:
#0 /Users/myuser/Documents/Projects/myapp/vendor/noahheck/e_pdostatement/src/EPDOStatement.php(25): Whoops\Run->handleError(8192, 'Return type of ...', '/Users/myuser/...', 80)
#1 /Users/myuser/Documents/Projects/myapp/vendor/composer/ClassLoader.php(571): include('/Users/myuser/...')
#2 /Users/myuser/Documents/Projects/myapp/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/Users/myuser/...')
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass('EPDOStatement\\E...')
#4 /Users/myuser/Documents/Projects/myapp/src/php/Database/DBConnection.php(21): PDO->setAttribute(13, Array)
[...]

I'm using Whoops for catching exceptions while in "debug" mode on my site.

I'm using PHP 8.1.11 and the version 2.3.1 of the package via composer.

Here is the content of the DBConnection class:

namespace App\Database;

use App\Utils\Config;
use PDO;

class DBConnection {

    /**
     * @var PDO
     */
    private static $pdo;

  public static function getPDO(): PDO {
    if (!isset(self::$pdo)) {
      $dsn = "mysql:host=" . $_ENV['DB_HOST'] . ";dbname=" . $_ENV['DB_NAME'];
      $user = $_ENV['DB_USER'];
      $passwd = $_ENV['DB_PASSWORD'];
      self::$pdo = new PDO($dsn, $user, $passwd);
      if (Config::isDebugEnabled()) {
        self::$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array("EPDOStatement\EPDOStatement", [self::$pdo]));
      }
    }
    return self::$pdo;
  }
}

What could be the issue?
Thank you in advance for your support.

@noahheck
Copy link
Owner

noahheck commented Apr 4, 2023

Sorry for the late reply @yonicsurny (I've been away from work activities for a while).

This looks like an issue with the PHP version and a change in the bindParam method's signature. I haven't updated my packages for php-8 support ( 😞 ) yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants