From: Marcus Boerger Date: Fri, 24 Feb 2006 15:56:03 +0000 (+0000) Subject: - Add FETCH_PROPSLATE: fetch props after calling ctor X-Git-Tag: RELEASE_1_2~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=252ad869176fe337402915ec3dd3a9607dbf9356;p=php - Add FETCH_PROPSLATE: fetch props after calling ctor # Fixes bug #36428 --- diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 5b2c2529df..e9ff63e48a 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -1238,6 +1238,7 @@ void pdo_dbh_init(TSRMLS_D) #if PHP_MAJOR_VERSION > 5 || PHP_MINOR_VERSION >= 1 REGISTER_PDO_CLASS_CONST_LONG("FETCH_SERIALIZE",(long)PDO_FETCH_SERIALIZE); #endif + REGISTER_PDO_CLASS_CONST_LONG("FETCH_PROPSLATE",(long)PDO_FETCH_PROPSLATE); REGISTER_PDO_CLASS_CONST_LONG("FETCH_NAMED",(long)PDO_FETCH_NAMED); REGISTER_PDO_CLASS_CONST_LONG("ATTR_AUTOCOMMIT", (long)PDO_ATTR_AUTOCOMMIT); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 0b00b43885..9a122d294c 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -838,6 +838,18 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, return 0; } } + if (ce->constructor && (flags & PDO_FETCH_PROPSLATE)) { + stmt->fetch.cls.fci.object_pp = &return_value; + stmt->fetch.cls.fcc.object_pp = &return_value; + if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc TSRMLS_CC) == FAILURE) { + pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor" TSRMLS_CC); + return 0; + } else { + if (stmt->fetch.cls.retval_ptr) { + zval_ptr_dtor(&stmt->fetch.cls.retval_ptr); + } + } + } } break; @@ -1000,7 +1012,7 @@ static int do_fetch(pdo_stmt_t *stmt, int do_bind, zval *return_value, switch (how) { case PDO_FETCH_CLASS: - if (ce->constructor) { + if (ce->constructor && !(flags & PDO_FETCH_PROPSLATE)) { stmt->fetch.cls.fci.object_pp = &return_value; stmt->fetch.cls.fcc.object_pp = &return_value; if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc TSRMLS_CC) == FAILURE) { diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 66b04dd44b..889a355bd6 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -98,6 +98,7 @@ enum pdo_fetch_type { #define PDO_FETCH_UNIQUE 0x00030000 /* fetch into groups assuming first col is unique */ #define PDO_FETCH_CLASSTYPE 0x00040000 /* fetch class gets its class name from 1st column */ #define PDO_FETCH_SERIALIZE 0x00080000 /* fetch class instances by calling serialize */ +#define PDO_FETCH_PROPSLATE 0x00100000 /* fetch props after calling ctor */ /* fetch orientation for scrollable cursors */ enum pdo_fetch_orientation { diff --git a/ext/pdo/tests/bug_36428.phpt b/ext/pdo/tests/bug_36428.phpt new file mode 100755 index 0000000000..1aea012c69 --- /dev/null +++ b/ext/pdo/tests/bug_36428.phpt @@ -0,0 +1,33 @@ +--TEST-- +PDO Common: PHP Bug #36428: Incorrect error message for PDO::fetchAll +--SKIPIF-- + +--FILE-- +exec("CREATE TABLE test (a VARCHAR(10))"); +$db->exec("INSERT INTO test (a) VALUES ('xyz')"); +$res = $db->query("SELECT a FROM test"); +var_dump($res->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_PROPSLATE, 'SimpleXMLElement', array(''))); + +?> +===DONE=== +--EXPECTF-- +array(1) { + [0]=> + object(SimpleXMLElement)#%d (1) { + ["a"]=> + string(3) "xyz" + } +} +===DONE===