Solved

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

Posted on 2006-11-17
10
568 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:zahidrahim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 13

Expert Comment

by:rhickmott
ID: 17965348
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
 
LVL 1

Author Comment

by:zahidrahim
ID: 17965386
well i commente or uncomment code in the function it still raises same error message

so what can be the solution????
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 17965424
Try removing the & from the function

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

to

=====================
function dbquery($sql){
=====================
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 1

Author Comment

by:zahidrahim
ID: 17965477
it does not produce the desired results then.
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 17965585
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
 
LVL 1

Author Comment

by:zahidrahim
ID: 17965830
yes u r very much right, but still is there no solution to this notice :( i want my code 100% accurate.........
0
 
LVL 13

Accepted Solution

by:
rhickmott earned 100 total points
ID: 17966099
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
 
LVL 14

Assisted Solution

by:Aamir Saeed
Aamir Saeed earned 100 total points
ID: 17968912
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

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question