Bug #68417 [Opn]: PDO extending objects loose their attributes

From: Date: Fri, 14 Nov 2014 08:16:45 +0000
Subject: Bug #68417 [Opn]: PDO extending objects loose their attributes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188588@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68417&edit=1

 ID:                 68417
 User updated by:    wuttke at hd-system dot de
 Reported by:        wuttke at hd-system dot de
 Summary:            PDO extending objects loose their attributes
 Status:             Open
 Type:               Bug
 Package:            PDO MySQL
 Operating System:   Ubuntu 14.0.4.1 LTS
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

The class itsself got lost when I copied the code in the textarea:

class mysqlPDO extends pdo
{
	public function  __construct($db_name, $host, $username, $passwd)
	{
		$this->attr = 'abc';
		parent::__construct('mysql:dbname='.$db_name.';host='.$host, $username,
$passwd, array(PDO::ATTR_PERSISTENT => true));
	}
}


Previous Comments:
------------------------------------------------------------------------
[2014-11-14 08:07:50] wuttke at hd-system dot de

Description:
------------
A class that extends pdo uses a persistant mysql-connection.
Different objects of this class are constructed, but as soon as a reference on one of these objects
is reused, all of the objects that exist at this moment loose their attributes.
Objects created after this procedure have their attributes.

Tested with php 5.9 and 5.18

Test script:
---------------
$o1 = new mysqlPDO('test_db', 'mydbserver.hds', 'root', '');
$o2 = new mysqlPDO('test_db', 'mydbserver.hds', 'root', '');
$o3 = new mysqlPDO('test_db', 'mydbserver.hds', 'root', '');
echo 'o1: '.$o1->attr.'<br>';
echo 'o2: '.$o2->attr.'<br>';
echo 'o3: '.$o3->attr.'<br>';
$o2 = new mysqlPDO('test_db', 'mydbserver.hds', 'root',
'');//At this point, o1-o3 loose their attributes
echo 'o1: '.$o1->attr.'<br>';
echo 'o2: '.$o2->attr.'<br>';
echo 'o3: '.$o3->attr.'<br>';
$o4 = new mysqlPDO('test_db', 'mydbserver.hds', 'root',
'');//This one has attributes again
echo 'o4: '.$o4->attr.'<br>';

Expected result:
----------------
o1: abc
o2: abc
o3: abc
o1: abc
o2: abc
o3: abc
o4: abc

Actual result:
--------------
o1: abc
o2: abc
o3: abc
o1:
o2:
o3:
o4: abc


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68417&edit=1


Thread (4 messages)

« previous php.bugs (#188588) next »