]> granicus.if.org Git - php/commitdiff
- Fixed bug #44409 (PDO::FETCH_SERIALIZE calls __construct())
authorFelipe Pena <felipe@php.net>
Mon, 23 Mar 2009 23:02:06 +0000 (23:02 +0000)
committerFelipe Pena <felipe@php.net>
Mon, 23 Mar 2009 23:02:06 +0000 (23:02 +0000)
  Patch by: matteo at beccati dot com

ext/pdo/pdo_stmt.c
ext/pdo/tests/bug_44409.phpt [new file with mode: 0644]

index 0c97aa0878be2d3ec9b76cd3971b1bff1131e051..66bd8b1413b68bcd65194649d77131eb343407c9 100755 (executable)
@@ -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 (file)
index 0000000..fe24fdf
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+PDO Common: Bug #44409 (PDO::FETCH_SERIALIZE calls __construct())
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
+require getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+$db = PDOTest::factory();
+
+$db->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
+        (
+        )
+
+)