|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43717 __construct() could be called after calling __set() by PDO
Submitted: 2007-12-31 09:22 UTC Modified: 2008-11-06 10:48 UTC
From: tohru at nakarika dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.5 OS: FreeBSD 6.1-RELEASE-p10
Private report: No CVE-ID: None
 [2007-12-31 09:22 UTC] tohru at nakarika dot com
when you call PDOStatement::fetch() with the fetch mode PDO::FETCH_CLASS 
PDO will create FooClass' instance.
And in the creation process PDO (or script engine?) calls
__set() method before calling FooClass' __construct().

Reproduce code:
class FooClass
  public function __construct($param)
    echo "FooClass::constructor\n";

  protected function &__set($name, $value)
    echo "FooClass::__set()\n";

$pdo = new PDO($dsn, ...);
$stmt = $pdo->prepare('SELECT * FROM ...');
$stmt->setFetchMode(PDO::FETCH_CLASS, FooClass, array('bar'));
$fooInst = $stmt->fetch();

Expected result:
The script should output strings in the following order:
1. FooClass::constructor
2. FooClass::__set()

Actual result:
1. FooClass::__set()
2. FooClass::constructor


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-01 07:48 UTC] crocodile2u at yandex dot ru
I'm experiencing the same problem with yesterday (2008-03-31) snapshot of php-5.3 and Kubuntu linux 7.10. By now, I have to workaround this by doing some additional checks, but I am quite sure that this behavior is more like a bug than a feature.
 [2008-11-06 10:48 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is expected, to allow people to access the data from the query within the ctor ...
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 17:01:28 2024 UTC