严格标准:仅变量应通过引用 PHP 5.4 分配
我将 PHP 版本升级到 5.4(XAMPP 1.7.3 到 1.8.0).现在我看到 Strict Standards 错误,对于 myDBconnection
:
I upgraded my PHP version to 5.4 (XAMPP 1.7.3 to 1.8.0). Now I see Strict Standards error, for myDBconnection
:
严格标准:C:xampphtdocsalousincludedbconn.php 第 4 行中的变量只能通过引用赋值
Strict Standards: Only variables should be assigned by reference in C:xampphtdocsalousincludedbconn.php on line 4
dbconn.php:
<?php
defined('_VALID') or die('Restricted Access!');
$conn = &ADONewConnection($config['db_type']); // <--- This Line 4
if ( !$conn->Connect($config['db_host'],
$config['db_user'],
$config['db_pass'],
$config['db_name'])) {
echo 'Could not connect to MySQL! Please check your database settings!';
die();
}
$conn->execute("SET NAMES 'utf8'");
?>
注意:我不需要使用此方法在 php.ini 中禁用 Strict Standards error_reporting = E_ALL &~E_NOTICE &~E_STRICT
!我想修复我的 PHP 代码.
Note: I don't need to disable Strict Standards in php.ini with this method error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
! I want to fix my PHP code.
推荐答案
您应该删除 &
(与号)符号,以便第 4 行看起来像这样:
You should remove the &
(ampersand) symbol, so that line 4 will look like this:
$conn = ADONewConnection($config['db_type']);
这是因为 ADONewConnection 已经通过引用返回了一个对象.根据文档,通过引用将引用的结果分配给对象从 PHP 5.3.0 开始,会产生 E_DEPRECATED 消息
This is because ADONewConnection already returns an object by reference. As per documentation, assigning the result of a reference to object by reference results in an E_DEPRECATED message as of PHP 5.3.0
相关文章