ID:               49521
 Updated by:       [email protected]
 Reported By:      waps at pisem dot net
-Status:           Open
+Status:           Verified
 Bug Type:         PDO related
 Operating System: Ubuntu 8.10 x64
 PHP Version:      5.2.10
 New Comment:

Confirmed. If the constructor sets default values for some fields, as
is typical, the constructor will overwrite the values just retrieved
from the database.

<?php
class Book {
        function __construct() {
                $this->title = "Default";
        }
}

$pdo = new PDO('mysql:dbname=books', 'root');
$statement = $pdo->prepare('SELECT * FROM book WHERE
title=\'Peopleware\'');
$statement->execute();
$obj = $statement->fetchObject('Book');
echo $obj->title; // Expected: Peopleware. Actual: Default
?> 


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

[2009-09-10 11:45:31] waps at pisem dot net

Description:
------------
Incorrect creating user object: set data before call constructor
method.

Reproduce code:
---------------
---
>From manual page: pdostatement.fetchobject
---

class Product {
    public function __construct() {
        echo 'create object, ';
    }
    public function __set($offset, $value) {
        echo 'set value, ';
    }
}

// fetch object
$stmt->fetchObject('Product', array());

Expected result:
----------------
Expected result: create object, set value, 

Actual result:
--------------
Actual result: set value, create object,


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


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

Reply via email to