#43717 [Opn->Bgs]: __construct() could be called after calling __set() by PDO
ID: 43717
Updated by: johannes@php.net
Reported By: tohru at nakarika dot com
-Status: Open
+Status: Bogus
Bug Type: PDO related
Operating System: FreeBSD 6.1-RELEASE-p10
PHP Version: 5.2.5
New Comment:
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 ...
Previous Comments:
------------------------------------------------------------------------
[2008-04-01 07:48:31] 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.
------------------------------------------------------------------------
[2007-12-31 09:22:22] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43717&edit=1
Thread (3 messages)