#43752 [Opn->Fbk]: PDO bindParam Mangles bound objects
ID: 43752
Updated by: felipe@php.net
Reported By: motoma at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: PDO related
Operating System: Windows
PHP Version: 5.2CVS-2008-01-04 (snap)
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[2008-01-15 18:22:12] motoma at gmail dot com
I will have to check later.
I doubt that this is the same error, this error is related directly to
the utilization of __toString() in PDO's bindParam() function.
------------------------------------------------------------------------
[2008-01-15 15:14:06] mjs at beebo dot org
Does the mangling happen without the ATTR_PERSISTENT? It looks like
this may be related to:
http://bugs.php.net/bug.php?id=43831
which concerns $this getting mangled
------------------------------------------------------------------------
[2008-01-04 18:32:58] motoma at gmail dot com
Description:
------------
I built a class with a __toString() member function. When I pass an
instance of this class to bindParam(), the object is overwritten with
the result of __toString().
The result from the code sample suggests that bindParam is overwriting
the value of the object with the object's __toString() value.
Reproduce code:
---------------
<?php
class test
{
private $a = 1;
public function __toString()
{
return strval($this->a);
}
}
$db = new PDO('mysql:host=localhost;dbname=test', 'root', '',
array(PDO::ATTR_PERSISTENT => true));
$obj = new test();
$prepared = $db->prepare('SELECT * FROM table1 WHERE 1 = :test');
var_dump($obj);
$prepared->bindParam('test', $obj);
var_dump($obj);
?>
Expected result:
----------------
object(test)#2 (1) {
["a:private"]=>
int(1)
}
object(test)#2 (1) {
["a:private"]=>
int(1)
}
Actual result:
--------------
object(test)#2 (1) {
["a:private"]=>
int(1)
}
string(1) "1"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43752&edit=1
Thread (5 messages)