|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 09:00:02 2025 UTC |
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.