|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-10-22 09:43 UTC] 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
]
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 01:00:01 2025 UTC |
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); }