ID: 37134
Updated by: [EMAIL PROTECTED]
Reported By: mark-phpbugs at vectrex dot org dot uk
-Status: Open
+Status: Assigned
Bug Type: PDO related
Operating System: Linux
PHP Version: 5.1.3RC2
-Assigned To:
+Assigned To: wez
New Comment:
Assigned to the maintainer.
Previous Comments:
------------------------------------------------------------------------
[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