ID: 28870
User updated by: rodolfo at rodsoft dot org
Reported By: rodolfo at rodsoft dot org
Status: Open
Bug Type: *Database Functions
Operating System: linux 2.6.7
PHP Version: 5.0.0RC3
New Comment:
A possible 'hack' that I've found is to bind the result to another
variable before cloning, and just after that restore the bind to the
original variable. This way the result is the expected one. It seems
that there's a problem of how mysqli_bind_result stores the variable
information while it is being cloned.
Previous Comments:
------------------------------------------------------------------------
[2004-06-21 18:35:56] rodolfo at rodsoft dot org
Description:
------------
If you pass to mysqli_bind_result a member variable of an object that
will be cloned and modified multiple times, each modification happens
in all cloned objects, as if they weren't cloned copies, but a single
copy of the object.
Reproduce code:
---------------
<?
/* Say you have a database called 'test' with one table
called 'test' that has one column called 'a' */
$db = new mysqli('localhost');
$db->select_db('test');
$stmt = $db->prepare('SELECT a FROM test');
$stmt->execute();
$result = new stdclass;
// Comment the next line to have the 'right' behaviour
$stmt->bind_result($result->a);
for($i = 0; $i<10; ++$i)
{
$result->a = $i;
$results[] = clone $result;
}
foreach($results as $result)
echo $result->a,"\n";
$db->close();
?>
Expected result:
----------------
0
1
2
3
4
5
6
7
8
9
Actual result:
--------------
9
9
9
9
9
9
9
9
9
9
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28870&edit=1