ID: 28870
Updated by: [EMAIL PROTECTED]
Reported By: rodolfo at rodsoft dot org
Status: Assigned
-Bug Type: Zend Engine 2 problem
+Bug Type: MySQL related
Operating System: *
PHP Version: 5.0.0
Assigned To: georg
New Comment:
$result->a / all bound variables are references. Hence the result shown
is correct. What we need is either disallowing clone or finding a way to
unbind the variables in clone and showing an error message in case
someone wants to execute a query with a cloned statement before
rebinding its columns.
Previous Comments:
------------------------------------------------------------------------
[2004-08-07 11:24:43] [EMAIL PROTECTED]
$result->a / all bound variables are references. Hence the result shown
is correct. What we need is either disallowing clone or finding a way to
unbind the variables in clone and showing an error message in case
someone wants to execute a query with a cloned statement before
rebinding its columns.
------------------------------------------------------------------------
[2004-08-07 11:01:48] [EMAIL PROTECTED]
The problem is that we use ZVAL_ADDREF for bind variables
(otherwise we had to rebind before every execute/fetch,
which would be a significant performance loss).
clone makes a binary copy of this object (and copies also
the reference). Not sure if it's a bug.
Changed category and assigned it to helly :)
------------------------------------------------------------------------
[2004-06-21 23:53:23] rodolfo at rodsoft dot org
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.
------------------------------------------------------------------------
[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