ID: 12692
Comment by: bugs dot php dot net-2004 dot 03 dot 27 at m-me dot dk
Reported By: metz at studenten dot net
Status: Bogus
Bug Type: Arrays related
Operating System: Linux 2.4.2
PHP Version: 4.0.6
New Comment:
Any idea if this is ever gonna be fixed?
Previous Comments:
------------------------------------------------------------------------
[2001-08-10 15:57:42] [EMAIL PROTECTED]
That's intentional
------------------------------------------------------------------------
[2001-08-10 13:27:43] metz at studenten dot net
test script:
// Class definiton used for reference testing
class Test
{
var $t = "x";
function Test(){}
function get_t()
{
return($this->t);
}
function set_t($t)
{
$this->t = $t;
}
}
// Array container reference test
$ref_one = new Test();
$ref_two = new Test();
$ref_three = new Test();
$ref_one->t = "one";
$ref_two->t = "two";
$ref_three->t = "three";
$refs = array();
$refs["one"] = &$ref_one;
$refs["two"] = &$ref_two;
$refs["three"] = &$ref_three;
print("<B>Test 7-1: (start)</B><BR>\n");
reset($refs);
for($idx = 0; $idx < count($refs); $idx++)
{
$key = key($refs);
$tmp = &$refs[$key];
print("${key} => " . $tmp->get_t() . "<BR>\n");
next($refs);
}
print("<BR>\n");
print("<B>Test 7-2: (using &current() to
adjust)</B><BR>\n");
reset($refs);
for($idx = 0; $idx < count($refs); $idx++)
{
$key = key($refs);
$tmp = ¤t($refs);
print("Setting: ${key} => ${idx}<BR>\n");
$tmp->set_t($idx);
next($refs);
}
reset($refs);
print("<B>Result:</B><BR>\n");
for($idx = 0; $idx < count($refs); $idx++)
{
$key = key($refs);
$tmp = &$refs[$key];
print("${key} => " . $tmp->get_t() . "<BR>\n");
next($refs);
}
print("<BR>\n");
print("<B>Test 7-3: (using direct method to
adjust)</B><BR>\n");
reset($refs);
for($idx = 0; $idx < count($refs); $idx++)
{
$key = key($refs);
$tmp = &$refs[$key];
print("Setting: ${key} => ${idx}<BR>\n");
$tmp->set_t($idx);
next($refs);
}
reset($refs);
print("<B>Result:</B><BR>\n");
for($idx = 0; $idx < count($refs); $idx++)
{
$key = key($refs);
$tmp = &$refs[$key];
print("${key} => " . $tmp->get_t() . "<BR>\n");
next($refs);
}
print("<BR>\n");
------------------------------------------------------------------------
[2001-08-10 13:21:25] metz at studenten dot net
When filling an array with reference to objects
the current() function does not return the reference to the
object but a copy of the object.
i.e.
$ref = ¤t($some_array);
returns a copy
work around:
$ref = &$some_array[key($some_array)];
returns the reference
Is this a bug or a difference in implementation?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=12692&edit=1