Improve parameter handling cod

This commit is contained in:
Ilia Alshanetsky 2011-09-13 16:36:29 +00:00
parent d2ff9ff591
commit 93763b11c9

View File

@ -1333,16 +1333,15 @@ static PHP_METHOD(PDOStatement, fetchObject)
long how = PDO_FETCH_CLASS;
long ori = PDO_FETCH_ORI_NEXT;
long off = 0;
char *class_name;
char *class_name = NULL;
int class_name_len;
zend_class_entry *old_ce;
zval *old_ctor_args, *ctor_args;
zval *old_ctor_args, *ctor_args = NULL;
int error = 0, old_arg_count;
PHP_STMT_GET_OBJ;
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sz",
&class_name, &class_name_len, &ctor_args)) {
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!a", &class_name, &class_name_len, &ctor_args)) {
RETURN_FALSE;
}
@ -1357,17 +1356,8 @@ static PHP_METHOD(PDOStatement, fetchObject)
old_arg_count = stmt->fetch.cls.fci.param_count;
do_fetch_opt_finish(stmt, 0 TSRMLS_CC);
switch(ZEND_NUM_ARGS()) {
case 0:
stmt->fetch.cls.ce = zend_standard_class_def;
break;
case 2:
if (Z_TYPE_P(ctor_args) != IS_NULL && Z_TYPE_P(ctor_args) != IS_ARRAY) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "ctor_args must be either NULL or an array" TSRMLS_CC);
error = 1;
break;
}
if (ctor_args) {
if (Z_TYPE_P(ctor_args) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(ctor_args))) {
ALLOC_ZVAL(stmt->fetch.cls.ctor_args);
*stmt->fetch.cls.ctor_args = *ctor_args;
@ -1375,15 +1365,16 @@ static PHP_METHOD(PDOStatement, fetchObject)
} else {
stmt->fetch.cls.ctor_args = NULL;
}
/* no break */
case 1:
}
if (class_name && !error) {
stmt->fetch.cls.ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
if (!stmt->fetch.cls.ce) {
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Could not find user-supplied class" TSRMLS_CC);
error = 1;
break;
}
} else if (!error) {
stmt->fetch.cls.ce = zend_standard_class_def;
}
if (!error && !do_fetch(stmt, TRUE, return_value, how, ori, off, 0 TSRMLS_CC)) {