#28870 [Opn->Asn]: mysqli_bind_result doesn't work with cloned objects

From: Date: Sat, 07 Aug 2004 09:01:50 +0000
Subject: #28870 [Opn->Asn]: mysqli_bind_result doesn't work with cloned objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-64216@lists.php.net to get a copy of this message
ID: 28870 Updated by: georg@php.net Reported By: rodolfo at rodsoft dot org -Status: Open +Status: Assigned -Bug Type: *Database Functions +Bug Type: Zend Engine 2 problem Operating System: linux 2.6.7 PHP Version: 5.0.0RC3 -Assigned To: georg +Assigned To: helly New Comment: 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 :) Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#64216) next »