ID: 25951
User updated by: dand at codemonkey dot ro
Reported By: dand at codemonkey dot ro
Status: Open
Bug Type: Unknown/Other Function
Operating System: Debian Linux 3.0
PHP Version: 4.3.3
New Comment:
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);
}
Previous Comments:
------------------------------------------------------------------------
[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