开发者

Assigning the return value of new by reference is deprecated in

I'm new to PHP and Im playing around with some code to see what i can learn/do. I have a simple little project where I am connecting to a mysql db and displaying the records of a table.

When I put all my code in one file, everything runs smooth, as soon as I try to put a chunk of code in a separte PHP file and use an include or require_once I get the error Assigning the return value of new by reference is deprecated in...PEAR\config.php yadda yadda

I've done some research and I understand that passing an object by reference (&obj) is no longer acceptable in PHP 5, that's fine, but no where in my code do I have an ampersand, and again, it all works fine if it's all in the same .php file. So i figure i might be doing something wrong with my includes or something.

This is the file that 'does the work' that i am calling from my main page with a require_once

include '/config.php';
// Open the database connection

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting t开发者_StackOverflow中文版o mysql');
mysql_select_db($dbname);

        //Define and run the query
        $query = "SELECT * FROM wp_posts";
    $result = mysql_query($query);

    echo mysql_error();

        //Close the db connection
    mysql_close();

    echo "<table><tr><td>Post Title</td><td>Post Status</td><td>Post Date</td></tr>";

        //Loop through result set and display data

        while($tdata=mysql_fetch_array($result))
        {
            echo "<tr><td>$tdata[post_title]</td><td> $tdata[post_status]</td><td> $tdata[post_date]</td></tr>";     // name class and mark will be printed with one line break
    }

        echo "</table>";

Anyways, I know my code isn't beautiful, Im still trying to figure it all out. Thanks for any help you can provide.

Additional Information: Ok, I know I'm a complete noob on this include stuff, and i apologize. Cant quite wrap my head around it all yet. But here's some additional info. Here is the full text of the error message I'm receving (NOTE: My code still runs and my table DOES still display)

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config\Container.php on line 111

Again, I'm using netBeans as my IDE, so in my Netbeans i went to Tools-Options and went to PHP and set C:\xampp\php\PEAR as the Global include path (Whatever the heck that means, but nonetheless it seemed like a good idea).

I guess if my include path is set right (/xampp/php...) then why am I still receiving the error. Grrr. Thanks for all your help guys.


It's the third party library you're using that's causing the problem, it's out of date and is using such things as returning by reference which are no longer considered good practice. You should upgrade the library in question. From what you've written I'm guessing it's this library. http://pear.php.net/package/Config/redirected

Try running pear upgrade config from the shell.


Your include path might be set in the wrong order.

The script seems to prefer the PEAR include directory over the current working directory. There are several ways to fix this:

1. use absolute includes

For instance, in your case:

include dirname(__FILE__) . 'config.php'; // pre-PHP 5.3
include __DIR__ . 'config.php'; // PHP 5.3

2. change the include path

To read more about this, see this page in the php.net documentation


Open your config.php and go to line 89 and remove the & after =

from:

"$this->container =& new Config_Container('section', 'root');"

to:

"$this->container = new Config_Container('section', 'root');"

Same goes to line 166.


it is simply pear package error which describes the problem about the assignment. so we can normally replace the assignment of =& with = in the given line of the error statement.that will solve our problem.


I had similar problem.The solution is change name of your file. config.php gets a file in pear folder not your config file.


Just run C:\xampp\php\pear-update.bat and restart the Apache server (On Windows macchine). For linux macchine follow the instuctions of GordonM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜