php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68417 PDO extending objects loose their attributes
Submitted: 2014-11-14 08:07 UTC Modified: 2020-09-20 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: wuttke at hd-system dot de Assigned: cmb (profile)
Status: No Feedback Package: PDO MySQL
PHP Version: Irrelevant OS: Ubuntu 14.0.4.1 LTS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: wuttke at hd-system dot de
New email:
PHP Version: OS:

 

 [2014-11-14 08:07 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-14 08:16 UTC] wuttke at hd-system dot de
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));
	}
}
 [2020-09-01 13:35 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-09-01 13:35 UTC] cmb@php.net
Can you still reproduce this with any of the actively supported
PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2020-09-20 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC