#33977 [NEW]: Only variable references should be returned by reference is buggy

From: Date: Wed, 03 Aug 2005 12:24:57 +0000
Subject: #33977 [NEW]: Only variable references should be returned by reference is buggy
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82874@lists.php.net to get a copy of this message
From:             kulakov74 at yandex dot ru
Operating system: Linux
PHP version:      4.4.0
PHP Bug Type:     Scripting Engine problem
Bug description:  Only variable references should be returned by reference is buggy

Description:
------------
Our hosting has upgraded to 4.4.0 and we got the famous notice on
returning variable reference. But after fixing my code to comply weith the
notice I found it is still displayed at certain circumstances.
Unfortunately, I could not isolate the code that behaves this way because
of the scripts complexity so I cannot provide a simple code that
reproduces it. While trying to figure out what was the reason I found that
many minor changes, apparently absolutely not relating to the problem,
could prevent the notice from beaing displayed, while otherwise it is
displayed. It could be simple output directly before or even anywhere in
the script, changing the value of the dummy variable that is returned
instead of false, for ex.

$oNewNode=null;
//...
return $oNewNode;

produced the notice while 

$oNewNode=0;

with the same code did not. Logging to a file, changing the line at which
the dummy assignment is done and a lot of other changes randomly toggle
the irrelevant notice off. I have a script that generates pages html and
the same code works with some pages but displays the notice with others;
then changing it results in the contrary thing. Finally, I found one
bug-proof solution that worked everywhere: 

$oNewNode=&$oNewNode;	return $oNewNode;

but overall working around the problem in the 4.4.0 release has left a
very unpleasant feeling of a buggy system. 

Reproduce code:
---------------
This does not reproduce the problem - it's just the piece of code I worked
with and I added all the lines I tried to prevent the notice. 

function &add($mixKey, $mixVal=array()){
//Add: either a pair $mixKey=>$mixVal,
//or a node $mixKey with values $mixVal, or an array of pairs $mixKey

//WORKED BUT NOT ALWAYS
$oNewNode=null; $oNewNode=false;
//WORKED ALMOST ALWAYS
$oNewNode=0; $oNewNode=1; 

//array
if (is_array($mixKey)){
	foreach($mixKey as $n => $v) $this->add($n, $v);
	//WORKED NOT ALWAYS
	$oNewNode=0;
	}
//string or a simple array
else if (!is_array($mixVal) || key($mixVal)===0){
	$this->hashValues[$mixKey]=$mixVal;
	//WORKED NOT ALWAYS
	$oNewNode=0;
	}
//node
else{
	$oNewNode=&new Node($mixVal, $this->bCleanup);
	if (!@$this->aNodeGroups[$mixKey]){
		$this->aNodeGroups[$mixKey]=array();
		}
	$this->aNodeGroups[$mixKey][]=&$oNewNode;
	//THIS FOR A REASON RESULTED IN EVEN MORE NOTICES UNLIKE THE COMMON
RETURN!
	return $oNewNode;
	}

//NO EFFECT FOR A REASON
if (!isset($oNewNode)) $oNewNode=0;

//THE SOLUTION
$oNewNode=&$oNewNode;

return $oNewNode;
}

Expected result:
----------------
No notices

Actual result:
--------------
A few notices for some pages, none for others

-- 
Edit bug report at http://bugs.php.net/?id=33977&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33977&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33977&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33977&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33977&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33977&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33977&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33977&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33977&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33977&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33977&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=33977&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=33977&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33977&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33977&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33977&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33977&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33977&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33977&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33977&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33977&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#82874) next »