问题
I Upgrade MyPHP Version To 5.4 (Xampp 1.7.3 to 1.8.0). Now I see Strict Standards error, for myDBconnection
:
Strict Standards: Only variables should be assigned by reference in C:\xampp\htdocs\alous\include\dbconn.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'");
?>
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.
回答1:
You should remove the &
(ampersand) symbol, so that line 4 will look like this:
$conn = ADONewConnection($config['db_type']);
From php's manual on assignment by reference:
As of PHP 5, the new operator returns a reference automatically, so assigning the result of new by reference results in an E_DEPRECATED message in PHP 5.3 and later, and an E_STRICT message in earlier versions.
回答2:
It's because you're trying to assign an object by reference. Remove the ampersand and your script should work as intended.
来源:https://stackoverflow.com/questions/11777908/strict-standards-only-variables-should-be-assigned-by-reference-php-5-4