ID:               37134
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mark-phpbugs at vectrex dot org dot uk
-Status:           Assigned
+Status:           Bogus
 Bug Type:         PDO related
-Operating System: Linux
+Operating System: *
-PHP Version:      5.1.3RC2
+PHP Version:      *
-Assigned To:      wez
+Assigned To:      hell
 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

This is by design.


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

[2006-04-19 09:58:11] [EMAIL PROTECTED]

Assigned to the maintainer.

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

[2006-04-19 09:29:49] mark-phpbugs at vectrex dot org dot uk

Description:
------------
PDOStatement::fetchObject calls constructor after populating fields,
which is not what I expected.

I expected it to call __construct() first, then populate fields.

Reproduce code:
---------------
<?php
        /* Test case for PDOStatement::fetchObject('ClassName')
         * Vars populated before constructor is run.
         */
        
        $db = new PDO("sqlite::memory:");
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $db->exec("CREATE TABLE person (id INTEGER NOT NULL, name
varchar(100))");
        $db->exec("INSERT INTO person(id, name) VALUES (1, 'Fred')");
        
        class Person {
                var $id;
                var $name;
                function __construct() {
                        $this->id = -1;
                }
        }
        
        $st = $db->query('SELECT * FROM person');
        $fred = $st->fetchObject('Person');
        
        print_r($fred);
?>


Expected result:
----------------
$fred->id should be 1

As the constructor will be called before variable population.

Actual result:
--------------
$fred->id is -1

Because the constructor is called after variable population.


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


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

Reply via email to