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

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

diff --git a/NEWS b/NEWS
index e25140588adde2374f9c88b523d6719d6a41383d..0861f7ba44059ad6e3f7b8f3ec37f68de73f87e8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 200?, PHP 5.3.0 RC 2
+- Fixed bug #44409 (PDO::FETCH_SERIALIZE calls __construct()).
+  (matteo at beccati dot com)
 
 24 Mar 2009, PHP 5.3.0 RC 1
 - Upgraded bundled sqlite to version 3.6.11. (Scott)
@@ -22,7 +24,7 @@ PHP                                                                        NEWS
 - Fixed bug #47572 (Undefined constant causes segmentation fault). (Felipe)
 - Fixed bug #47549 (get_defined_constants() return array with broken
   array categories). (Ilia)
-- Fixed Bug #47443 (metaphone('scratch') returns wrong result). (Felipe)
+- Fixed bug #47443 (metaphone('scratch') returns wrong result). (Felipe)
 - Fixed bug #47438 (mysql_fetch_field ignores zero offset). (Johannes)
 - Fixed bug #47398 (PDO_Firebird doesn't implements quoter correctly). (Felipe)
 - Fixed bug #47390 (odbc_fetch_into - BC in php 5.3.0). (Felipe)
index 74587af9b21e764d89ef0ad8cc0870d46800122c..698ef564d8b430dcf0108fd249ab3acf95e9f4f4 100755 (executable)
@@ -1241,7 +1241,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
+        (
+        )
+
+)
index 5886a82c88c16c8fdd0c833b396cc23ec0dfb5f0..db8f2f5eaab4ce557fcafa0091da63f32807ab28 100644 (file)
@@ -131,7 +131,6 @@ object(myclass)#4 (1) {
 
 Using PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE to fetch the object from DB and unserialize it...
 myclass::unserialize('C:7:"myclass":19:{Data from serialize}')
-myclass::__construct(PDO shall not call __construct())
 object(myclass)#%d (1) {
   ["myprotected":protected]=>
   string(19) "a protected propery"
index ba29e6a53ec58321c68ee8844fccf9358de19106..e9b231cfdd9025aef45f37870acdd708896c0915 100644 (file)
@@ -80,17 +80,14 @@ object(myclass)#%d (0) {
 
 And now magic PDO using fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE)...
 myclass::unserialize('Data fetched from DB to be given to unserialize()')
-myclass::__construct('Called by PDO') - note that it must not be called when unserializing
 object(myclass)#%d (0) {
 }
 myclass::unserialize('Data fetched from DB to be given to unserialize()')
-myclass::__construct(NULL) - note that it must not be called when unserializing
 object(myclass)#%d (0) {
 }
 
 And now PDO using setFetchMode(PDO::FETCH:CLASS|PDO::FETCH_SERIALIZE) + fetch()...
 myclass::unserialize('Data fetched from DB to be given to unserialize()')
-myclass::__construct('Called by PDO') - note that it must not be called when unserializing
 object(myclass)#%d (0) {
 }
 done!