|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41971 PDOStatement::fetch and PDOStatement::setFetchMode causes unexpected behavior
Submitted: 2007-07-11 23:20 UTC Modified: 2007-07-31 22:48 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: joelboh at gmail dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.2CVS-2007-07-12 OS: Linux
Private report: No CVE-ID:
 [2007-07-11 23:20 UTC] joelboh at gmail dot com
When using PDOStatement::setFetchMode() with PDO::FETCH_CLASS and PDO::FETCH_PROPS_LATE a call without arguments to PDOStatement::fetch() wont work.

Reproduce code:
class Person
    public $parameter;
    public function __construct($parameter)
        $this->parameter = $parameter;

$db = new PDO("sqlite::memory:");
$db->exec("CREATE TABLE person (id INTEGER NOT NULL, name varchar(100))");
$db->exec("INSERT INTO person(id, name) VALUES (1, 'Sven')");

$stmt = $db->query('SELECT * FROM person');
$stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person', array(0 => 'Parameter'));
/* To get the expected result you must use: $stmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE);
Should that really be needed? */
$obj = $stmt->fetch();

Expected result:
Person Object ( [parameter] => Parameter [id] => 1 [name] => Sven )

Actual result:
$obj is false

If PDO::FETCH_PROPS_LATE is not used in PDOStatement::setFetchMode and PDOStatement::fetch() is called without arguments you get the expected result.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-12 13:29 UTC] joelboh at gmail dot com
No change in the result, $obj is still false with snapshot: php5.2-200707121230
 [2007-07-31 22:48 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 03:01:31 2015 UTC