Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

Strict Standards: Only variables should be assigned by reference PHP 5.4

I upgraded my PHP 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: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'");
?>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should remove the & (ampersand) symbol, so that line 4 will look like this:

$conn = ADONewConnection($config['db_type']);

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...