Php 严格标准:声明应与PDO声明兼容
我试着运行其他团队开发的代码。我配置并运行了项目,但我得到了以下错误,这对我来说是新的 严格的标准:DB_语句_1::execute()的声明应该是 与PDOStatement::execute($bound_input_params=NULL)兼容 /第12行的virtualhosts/libolution/DB/Statement.1.php 严格标准:DB_语句_1::fetch()的声明应与PDOStatement::fetch($how=NULL,$orientation=NULL, $offset=NULL)位于/virtualhosts/libolution/DB/Statement.1.php的第行 十二, 第12行如下Php 严格标准:声明应与PDO声明兼容,php,mysql,pdo,zend-framework2,Php,Mysql,Pdo,Zend Framework2,我试着运行其他团队开发的代码。我配置并运行了项目,但我得到了以下错误,这对我来说是新的 严格的标准:DB_语句_1::execute()的声明应该是 与PDOStatement::execute($bound_input_params=NULL)兼容 /第12行的virtualhosts/libolution/DB/Statement.1.php 严格标准:DB_语句_1::fetch()的声明应与PDOStatement::fetch($how=NULL,$orientation=NULL,
/**
* 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);
}
那么哪一个被覆盖
多亏了所有的,这可能是由于PHP版本的升级,以及PHP如何处理PHP5.4中的不同错误+ 首先,您可以禁用严格错误以消除此错误,如下所示:
error_reporting(E_ALL ^ E_STRICT);
注意E_STRICT-这是PHP5.4的新特性+
但是,如果您想保留严格的错误,可以通过更改代码来消除它们。您需要确保重写的类具有正确的原型/定义,以消除错误
案例1)
删除“array”类型提示,因为父类没有,这将消除第一个错误等。正在PDO之上构建DB包装器?0_oI.e。您的方法签名必须与您要覆盖的方法签名相匹配。但是在DB packageLooks中没有DB_IStatement_1接口或类,就像一个非常糟糕的包一样。我已经提到了同一个包中的所有类。谢谢,我按照您所说的更改了代码,Ist警告消失了,但实际问题是我得到了它“无法连接到数据库”。这是一个关键问题。但这与您在问题中所说的完全不同-这两个错误与连接到数据库无关。。
error_reporting(E_ALL ^ E_STRICT);
class DB_Statement_1 extends PDOStatement implements DB_IStatement_1
{
public function execute($args = NULL) { ... }
....
}