php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43752 PDO bindParam Mangles bound objects
Submitted: 2008-01-04 18:32 UTC Modified: 2009-09-23 21:17 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: motoma at gmail dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.2CVS-2008-01-04 (snap) OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: motoma at gmail dot com
New email:
PHP Version: OS:

 

 [2008-01-04 18:32 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-15 15:14 UTC] 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-15 18:22 UTC] 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.
 [2009-02-13 22:22 UTC] felipe@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-02-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-09-23 21:17 UTC] uw@php.net
A duplicate of http://bugs.php.net/bug.php?id=41027 ?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 22:01:31 2024 UTC