php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50875 Objects loaded using PDO are *empty* when the __construct method is called
Submitted: 2010-01-28 20:17 UTC Modified: 2010-04-25 20:20 UTC
Votes:10
Avg. Score:5.0 ± 0.0
Reproduced:9 of 9 (100.0%)
Same Version:9 (100.0%)
Same OS:7 (77.8%)
From: contact at weirdog dot com Assigned: felipe (profile)
Status: Closed Package: PDO related
PHP Version: 5.2.12 OS: Linux
Private report: No CVE-ID: None
 [2010-01-28 20:17 UTC] contact at weirdog dot com
Description:
------------
Objects loaded using PDO are *empty* (as in "they have no properties") when the __construct() method is called.

This was not the case before version 5.2.12. Usualy, properties loaded from the database where already applyed when the __construct() method was called.

This is really annoying since further initialisation during the __construct() method is now impossible.

Reproduce code:
---------------
class WdActiveRecord
{
	public function __construct()
	{
		var_dump($this);
	}
}

$stmt = $db->query('SELECT * FROM nodes WHERE nid = 498');

$stmt->fetchObject('WdActiveRecord');

Expected result:
----------------
object(site_pages_WdActiveRecord)[68]
  public 'nid' => string '498' (length=3)
  public 'parentid' => string '0' (length=1)
  public 'pattern' => string 'about' (length=5)
  public 'weight' => string '9' (length=1)
  public 'layout' => string 'page' (length=5)
  public 'location' => string '' (length=22)
  public 'is_navigation_excluded' => string '0' (length=1)
  public 'is_restricted' => string '0' (length=1)
  public 'uid' => string '9' (length=1)
  public 'title' => string '? propos' (length=16)
  public 'slug' => string 'apropos' (length=15)
  public 'created' => string '2009-11-29 18:13:17' (length=19)
  public 'modified' => string '2009-11-29 18:17:29' (length=19)
  public 'constructor' => string 'site.pages' (length=10)
  public 'is_online' => string '1' (length=1)
  public 'language' => string '' (length=0)
  public 'tnid' => string '0' (length=1)
  public 'is_translation_deprecated' => string '0' (length=1)

Actual result:
--------------
object(site_pages_WdActiveRecord)#68 (0) { }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-11 23:29 UTC] michael at twofishcreative dot com
See this post to the PHP internals list, and follow ups, about this change http://news.php.net/php.internals/46748.
 [2010-02-15 23:00 UTC] felipe@php.net
Please try using this snapshot:

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

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


 [2010-02-19 23:19 UTC] contact at weirdog dot com
There are no binaries snapshots currently available. I tried with the QA Release of PHP 5.2 (5.2.13RC2) and it doesn't work either, which might not be surprising since the snapshot is older than the modified status date of the bug report.
 [2010-02-23 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".
 [2010-03-02 20:27 UTC] matt at mattread dot com
this was fixed in revision 294903. but was only fixed in trunk and the 5.3 branch. 
Is this fix not going to be in 5.2 branch?

http://svn.php.net/viewvc?view=revision&revision=294903
 [2010-04-25 20:20 UTC] felipe@php.net
-Status: No Feedback +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-04-25 20:20 UTC] felipe@php.net
It was already fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 09:01:28 2024 UTC