php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43831 $this gets mangled when extending PDO with persistent connection
Submitted: 2008-01-13 20:55 UTC Modified: 2009-02-13 02:24 UTC
Votes:3
Avg. Score:3.0 ± 1.6
Reproduced:2 of 3 (66.7%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: mjs at beebo dot org Assigned: felipe (profile)
Status: Closed Package: PDO related
PHP Version: 5.2CVS, 5.3CVS, 6CVS OS: OS X/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mjs at beebo dot org
New email:
PHP Version: OS:

 

 [2008-01-13 20:55 UTC] mjs at beebo dot org
Description:
------------
The class of $this changes after the instantiation of a class which 
extends PDO, and which specifies PDO::ATTR_PERSISTENT attribute.



Reproduce code:
---------------
class Foo extends PDO {
	function __construct($dsn) {
		parent::__construct($dsn, null, null, array(PDO::ATTR_PERSISTENT => true));
	}
}

class Baz extends PDO {
	function __construct($dsn) {
		parent::__construct($dsn, null, null, array(PDO::ATTR_PERSISTENT => true));
	}
}

class Bar extends Baz {
	function quux() {
		echo get_class($this), "\n";
		$foo = new Foo("sqlite::memory:");
		echo get_class($this), "\n";
	}
}

$bar = new Bar("sqlite::memory:");
$bar->quux();



Expected result:
----------------
Bar
Bar

i.e. get_class($this) returns the same value each time

Actual result:
--------------
Bar
Foo

i.e. $this gets mangled

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-24 21:12 UTC] felipe@php.net
/home/felipe/dev/php5/ext/pdo/pdo_dbh.c(1516) :  Freeing 0x088CEA34 (44 bytes), script=../bug.php
[Fri Oct 24 18:55:13 2008]  Script:  '../bug.php'
/home/felipe/dev/php5/ext/pdo/pdo_dbh.c(1517) :  Freeing 0x088D7844 (32 bytes), script=../bug.php
/home/felipe/dev/php5/Zend/zend_alloc.c(2391) : Actual location (location was relayed)
=== Total 2 memory leaks detected ===

 [2008-10-24 21:13 UTC] felipe@php.net
/home/felipe/dev/php5/ext/pdo/pdo_dbh.c(1516) :  Freeing 0x088CEA34 (44 bytes), script=../bug.php
[Fri Oct 24 18:55:13 2008]  Script:  '../bug.php'
/home/felipe/dev/php5/ext/pdo/pdo_dbh.c(1517) :  Freeing 0x088D7844 (32 bytes), script=../bug.php
/home/felipe/dev/php5/Zend/zend_alloc.c(2391) : Actual location (location was relayed)
=== Total 2 memory leaks detected ===

 [2009-02-02 18:55 UTC] dennis at born05 dot nl
A simpler case might be:

class MyPDO extends PDO {}

$bar = new PDO("sqlite::memory:", null, null, 
array(PDO::ATTR_PERSISTENT => true));
$baz = new MyPDO("sqlite::memory:", null, null, 
array(PDO::ATTR_PERSISTENT => true));

var_dump ($bar);
var_dump ($baz);

It looks like it internally caches the object, not just the 
connection..

Tested on Fedora Core 6, latest snaps of both 5.2 and 5.3 branch.
 [2009-02-13 02:24 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC