From: Felipe Pena Date: Mon, 23 Mar 2009 23:02:06 +0000 (+0000) Subject: - Fixed bug #44409 (PDO::FETCH_SERIALIZE calls __construct()) X-Git-Tag: php-5.4.0alpha1~191^2~4077 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11dde4a7c5240dd5487353704def5207bd16791b;p=php - Fixed bug #44409 (PDO::FETCH_SERIALIZE calls __construct()) Patch by: matteo at beccati dot com --- diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 0c97aa0878..66bd8b1413 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -1239,7 +1239,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, switch (how) { case PDO_FETCH_CLASS: - if (ce->constructor && !(flags & PDO_FETCH_PROPS_LATE)) { + if (ce->constructor && !(flags & (PDO_FETCH_PROPS_LATE | PDO_FETCH_SERIALIZE))) { stmt->fetch.cls.fci.object_ptr = return_value; stmt->fetch.cls.fcc.object_ptr = return_value; if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc TSRMLS_CC) == FAILURE) { diff --git a/ext/pdo/tests/bug_44409.phpt b/ext/pdo/tests/bug_44409.phpt new file mode 100644 index 0000000000..fe24fdfb86 --- /dev/null +++ b/ext/pdo/tests/bug_44409.phpt @@ -0,0 +1,51 @@ +--TEST-- +PDO Common: Bug #44409 (PDO::FETCH_SERIALIZE calls __construct()) +--SKIPIF-- + +--FILE-- +exec("CREATE TABLE test (dat varchar(100))"); +$db->exec("INSERT INTO test (dat) VALUES ('Data from DB')"); + +class bug44409 implements Serializable +{ + public function __construct() + { + printf("Method called: %s()\n", __METHOD__); + } + + public function serialize() + { + return "any data from serizalize()"; + } + + public function unserialize($dat) + { + printf("Method called: %s(%s)\n", __METHOD__, var_export($dat, true)); + } +} + +$stmt = $db->query("SELECT * FROM test"); + +print_r($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, "bug44409")); + +?> +--EXPECT-- +Method called: bug44409::unserialize('Data from DB') +Array +( + [0] => bug44409 Object + ( + ) + +)