Only variable references should be returned by reference

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tornup
Forum Newbie
Posts: 2
Joined: Tue Apr 11, 2006 9:55 am

Only variable references should be returned by reference

Post by tornup »

Hi,

I am trying to install Xoops Custom Installation, and I am getting the following error
"Notice: Only variable references should be returned by reference in C:\Apache2\Apache2\htdocs\xoop\html\install\class\textsanitizer.php on line 96"

Line 96 of textsanitizer.php is:

Code: Select all

/* for displaying data in html textbox forms */

function &htmlSpecialChars($text)
{  
	return preg_replace("/&/i", '&', htmlspecialchars($text, ENT_QUOTES));
}
Can someone help me figure out what is wrong here. Thanks.

Nina
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Only variable references should be returned by reference

Post by timvw »

Try:

Code: Select all


/* for displaying data in html textbox forms */

function &htmlSpecialChars($text)
{  
  $result = preg_replace("/&/i", '&', htmlspecialchars($text, ENT_QUOTES));
  return $result;
}
tornup
Forum Newbie
Posts: 2
Joined: Tue Apr 11, 2006 9:55 am

Re: Only variable references should be returned by reference

Post by tornup »

Thanks so much. It worked!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

This call should probably not use references at all, and just be:

Code: Select all

function htmlSpecialChars($text)
{ 
   return preg_replace("/&/i", '&', htmlspecialchars($text, ENT_QUOTES));
}
(#10850)
Post Reply