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

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

« previous php.bugs (#64217) next »