严格标准:声明应与PDO声明兼容

Strict Standards: Declaration should be compatible with PDO statement

我正在尝试 运行 其他团队开发的代码。我配置了 运行 项目,但我收到以下对我来说是新的错误。

Strict Standards: Declaration of DB_Statement_1::execute() should be compatible with PDOStatement::execute($bound_input_params = NULL) in /virtualhosts/libolution/DB/Statement.1.php on line 12

Strict Standards: Declaration of DB_Statement_1::fetch() should be compatible with PDOStatement::fetch($how = NULL, $orientation = NULL, $offset = NULL) in /virtualhosts/libolution/DB/Statement.1.php on line 12

第 12 行在此处。

/**
 * A statement class that implements DB_IStatement_1
 * NOTE: in most cases, you should be type-hinting for DB_IStatement_1
 * @author Andrew Minerd <andrew.minerd@sellingsource.com>
 */ 
   following line is #12
  class DB_Statement_1 extends PDOStatement implements DB_IStatement_1
{   public function execute(array $args = NULL)
    {
        // apparently, PDO counts the number of arguments to indicate missing
        // optional parameters, rather than relying on a default value
        $result = ($args !== NULL)
            ? parent::execute($args)
            : parent::execute();

        if ($result === FALSE)
        {
            throw new PDOException('Could not execute statement');
        }
        return $result;
    }

    /**
     * Fetches a single row
     *
     * @param int $fetch_mode
     * @return mixed
     */
    public function fetch($fetch_mode = DB_IStatement_1::FETCH_ASSOC)
    {
        return parent::fetch($fetch_mode);
    }

同一个包中有以下 类 个。

DatabaseConfigPool.1.php  MSSQLAdapter.1.php           MySQL4Adapter.1.php           ODBCConfig.1.php              TransactionAbortedException.1.php
EmulatedPrepare.1.php     MSSQLAdapterException.1.php  MySQL4AdapterException.1.php  PoolConfig.1.php              TransactionManager.1.php
FailoverConfig.1.php      MSSQLConfig.1.php            MySQL4StatementAdapter.1.php  Profiler                      Util
IConnection.1.php         MSSQLConfig.2.php            MySQLConfig.1.php             Query.1.php                   Util.1.php
IDatabaseConfig.1.php     MSSQLStatementAdapter.1.php  MySQLiAdapter.1.php           SQLiteConfig.1.php
IStatement.1.php          MultiplexConfig.1.php        MySQLiAdapterException.1.php  Statement.1.php
[vendorapi@808680-app2 DB]$ nano Statement.1.php

因此它们中的哪一个被覆盖了。

感谢大家

这可能是由于 PHP 版本的升级,以及 PHP 如何处理 PHP 5.4+

中的不同错误

首先,您可以像这样禁用严格错误以消除此错误:

error_reporting(E_ALL ^ E_STRICT);

注意 E_STRICT - 这是 PHP 5.4+

的新功能

但是,如果您想保留严格错误,可以通过更改代码来消除它们。您将需要确保 classes 重写具有正确的 prototype/definition 以消除错误。

案例 1)

class DB_Statement_1 extends PDOStatement implements DB_IStatement_1
{   
    public function execute($args = NULL) { ... }

    ....
}

删除 'array' 类型提示,因为父级 class 没有类型提示,这应该可以避免第一个错误等。