Browse Source

MFH:

- Fixed bug #44409 (PDO::FETCH_SERIALIZE calls __construct())
  Patch by: matteo at beccati dot com
experimental/5.3-FPM
Felipe Pena 18 years ago
parent
commit
861d51223f
  1. 4
      NEWS
  2. 2
      ext/pdo/pdo_stmt.c
  3. 51
      ext/pdo/tests/bug_44409.phpt
  4. 1
      ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_serialize.phpt
  5. 3
      ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_serialize_simple.phpt

4
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)

2
ext/pdo/pdo_stmt.c

@ -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) {

51
ext/pdo/tests/bug_44409.phpt

@ -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
(
)
)

1
ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_serialize.phpt

@ -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"

3
ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_serialize_simple.phpt

@ -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!
Loading…
Cancel
Save