php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tohru at nakarika dot com
New email:
PHP Version: OS:

 

 [2007-12-31 09:22 UTC] tohru at nakarika dot com
Description:
------------
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] johannes@php.net
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 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: Tue Jul 23 18:01:30 2024 UTC