#43752 [Com]: PDO bindParam Mangles bound objects
| From: | mjs at beebo dot org | Date: | Tue, 15 Jan 2008 15:14:06 +0000 |
| Subject: | #43752 [Com]: PDO bindParam Mangles bound objects | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-121301@lists.php.net to get a copy of this message | ||
ID: 43752
Comment by: mjs at beebo dot org
Reported By: motoma at gmail dot com
Status: Open
Bug Type: PDO related
Operating System: Windows
PHP Version: 5.2CVS-2008-01-04 (snap)
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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