Only variable references should be returned by reference in ...........

Helloo
       I have an application which developed in php4.4.0 now i am trying to upgrade it to php5.1.4
//Class File
class Database{
       function &dbquery($sql){
         /*
          i have commented all code
          */
        }
}

Now another calling file:
$vigappsdb = new Database();
$sql_query = "INSERT INTO VEHICLE (VEHICLE_NAME) VALUES ('$vehicle_name')";
$vresult=$vigappsdb->dbquery($sql_query);

it is generating notic:

Notice: Only variable references should be returned by reference in..............

Thanx in advance
LVL 1
zahidrahimAsked:
Who is Participating?
 
Robin HickmottConnect With a Mentor Software DeveloperCommented:
Code and Error looks similar too

http://codewalkers.com/forum/index.php?action=displaythread&forum=phphelp&id=664&realm=default

Difficult to say without looking at the class.

But there should be no reason why you need to return data in and out of functions by reference. You will prob have to take out the &'s and rewrite the class a bit.

class Database{

       function dbquery($sql){
                   $this->resultRef = mysql_query($query);
                   $this->result = mysql_fetch_array($this->resultRef);
                   
                   return $this->result;
        }

}

Your probably need to split this over two function though and query the database and contianlly pass the resultref back in order to get subsequent rows.
0
 
Robin HickmottSoftware DeveloperCommented:
We would probably need to see the function I have a similar wrapper class and it functions fine under php 5.

Quite a lot has been changed in php 5 class wise.

Try

$vigappsdb = new Database;
$sql_query = "INSERT INTO VEHICLE (VEHICLE_NAME) VALUES ('$vehicle_name')";
$vresult=$vigappsdb->dbquery($sql_query);

BUT by the notice I would conclude that its having issues with the & in front of the function name.

function &dbquery($sql){

This indicates that the return value is passed by reference.
0
 
zahidrahimAuthor Commented:
well i commente or uncomment code in the function it still raises same error message

so what can be the solution????
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Robin HickmottSoftware DeveloperCommented:
Try removing the & from the function

change
=====================
function &dbquery($sql){
=====================

to

=====================
function dbquery($sql){
=====================
0
 
zahidrahimAuthor Commented:
it does not produce the desired results then.
0
 
Robin HickmottSoftware DeveloperCommented:
Well it is only a notice so there is no reason why you have to do anything about it but these things have a nasty habit of coming back and biting you later on.

The only thing I can suggest is that you change your error_reporting level to exclude notices or rewrite your class so that it doesent return by reference.
0
 
zahidrahimAuthor Commented:
yes u r very much right, but still is there no solution to this notice :( i want my code 100% accurate.........
0
 
Aamir SaeedConnect With a Mentor Commented:
I think if you want to avoid such sort of Notice( s ), simply use
display_errors = Off
error_reporting(0);
ini_set('error_reporting', 0);

BOL!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.