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)
- 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)
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) {
--- /dev/null
+--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
+ (
+ )
+
+)
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"
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!