#50875 [NEW]: Objects loaded using PDO are *empty* when the __construct method is called

From: Date: Thu, 28 Jan 2010 20:17:13 +0000
Subject: #50875 [NEW]: Objects loaded using PDO are *empty* when the __construct method is called
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-147034@lists.php.net to get a copy of this message
From:             contact at weirdog dot com
Operating system: Linux
PHP version:      5.2.12
PHP Bug Type:     PDO related
Bug description:  Objects loaded using PDO are *empty* when the __construct method is called

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) { }

-- 
Edit bug report at http://bugs.php.net/?id=50875&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=50875&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=50875&r=trysnapshot53
Try a snapshot (PHP 6.0):            http://bugs.php.net/fix.php?id=50875&r=trysnapshot60
Fixed in SVN:                        http://bugs.php.net/fix.php?id=50875&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50875&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=50875&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=50875&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=50875&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=50875&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=50875&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=50875&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=50875&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=50875&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=50875&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50875&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50875&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=50875&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=50875&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=50875&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=50875&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=50875&r=mysqlcfg



Thread (6 messages)

« previous php.bugs (#147034) next »