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

Reply via email to