ID:          46624
 Updated by:  [EMAIL PROTECTED]
 Reported By: [EMAIL PROTECTED]
-Status:      Open
+Status:      Bogus
 Bug Type:    PDO related
 PHP Version: 5.2.6
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.


Previous Comments:
------------------------------------------------------------------------

[2008-11-19 20:14:47] [EMAIL PROTECTED]

Description:
------------
If you set the PDO fetch mode to PDO::FETCH_CLASS and fetch all results
from a result set (aka processed statement), the constructor is called
after the properties of the newly created object are set.

This is incorrect from the OO point of view, since the ctor may provide
sensible default values for properties and prepare the object overall.
Therefore property manipulation should happen after the ctor was called.

Reproduce code:
---------------
$db = $this->getTrackbackDbConection();
$select = $db->query( 'SELECT ... ;' );
$select->setFetchMode( PDO::FETCH_CLASS, 'myCustomClass' );
$result = $select->fetchAll();

class myCustomClass
{

    public $someProperty;

    public function __construct()
    {
       $this->someProperty = 'default'
    }
}


Expected result:
----------------
myCustomClass->$someProperty is overwritten by a value from the
database.

Actual result:
--------------
myCustomClass->$someProperty is overwritten by 'default' since
__construct() is called after the properties have been set in PDO.


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


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


Reply via email to