#25951 [Fbk->Bgs]: Error suppression operator + reference return statement => corrupt func. params

From: Date: Fri, 24 Oct 2003 02:29:56 +0000
Subject: #25951 [Fbk->Bgs]: Error suppression operator + reference return statement => corrupt func. params
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-49416@lists.php.net to get a copy of this message
 ID:               25951
 Updated by:       iliaa@php.net
 Reported By:      dand at codemonkey dot ro
-Status:           Feedback
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Debian Linux 3.0
 PHP Version:      4.3.3
 New Comment:

read above.


Previous Comments:
------------------------------------------------------------------------

[2003-10-23 22:29:41] iliaa@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

You should not return string offsets by reference. In PHP 5.0 this
would result in the following warning message:
Fatal error: Only variables or references can be returned by reference

------------------------------------------------------------------------

[2003-10-22 09:46:51] dand at codemonkey dot ro

Sorry, the actual code producing the results above is:

class Foo {
	var $hash;

	function  & getElement($name) {
		return @$this->hash[$name];
	}	
	
	function bar($a, $b, $c)
	{
		print "BAR: $a, $b, $c<br>";
	}	
}

$f = new Foo();

for ($k = 0; $k < 3; $k++) {
	$t = $f->getElement($k);
	$f->bar(1, 2, 3);
}

------------------------------------------------------------------------

[2003-10-22 09:43:40] dand at codemonkey dot ro

Description:
------------
The code + results should be pretty self explainatory.

A workaround would be to remove either the reference operator "&
getElement" or the error suppression operator "@$this->hash".

PS: I know that using @ instead of isset() is wrong, especially in this
situation...

Reproduce code:
---------------
class Foo {
	var $hash;

	function  & getElement($name) {
		return @$this->hash[$name];
	}	

	function bar($a, $b, $c, $d)
	{
		print "BAR: $a, $b, $c, $d<br>";
	}	
}

$f = new Foo();

for ($k = 0; $k < 3; $k++) {
	$t = $f->getElement($k);
	$f->bar(1, 2, 3, 4);
}

Expected result:
----------------
BAR: 1, 2, 3
BAR: 1, 2, 3
BAR: 1, 2, 3

Actual result:
--------------
BAR: 1, 2, 3
BAR: 3, 3, 3
BAR: 3, 3, 3

[If it helps, in PHP 4.1.2 the actual result is:
BAR: 3, 3, 3
BAR: 3, 3, 3
BAR: 3, 3, 3
]


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25951&edit=1


Thread (4 messages)

« previous php.bugs (#49416) next »