svn: /php/php-src/ branches/PHP_5_4/ext/pdo/pdo_stmt.c trunk/ext/pdo/pdo_stmt.c

From: Date: Tue, 13 Sep 2011 16:36:29 +0000
Subject: svn: /php/php-src/ branches/PHP_5_4/ext/pdo/pdo_stmt.c trunk/ext/pdo/pdo_stmt.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-66509@lists.php.net to get a copy of this message
iliaa Tue, 13 Sep 2011 16:36:29 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=316667 Log: Improve parameter handling cod Changed paths: U php/php-src/branches/PHP_5_4/ext/pdo/pdo_stmt.c U php/php-src/trunk/ext/pdo/pdo_stmt.c Modified: php/php-src/branches/PHP_5_4/ext/pdo/pdo_stmt.c =================================================================== --- php/php-src/branches/PHP_5_4/ext/pdo/pdo_stmt.c 2011-09-13 16:21:24 UTC (rev 316666) +++ php/php-src/branches/PHP_5_4/ext/pdo/pdo_stmt.c 2011-09-13 16:36:29 UTC (rev 316667) @@ -1333,16 +1333,15 @@ 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 @@ 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 @@ } 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)) { Modified: php/php-src/trunk/ext/pdo/pdo_stmt.c =================================================================== --- php/php-src/trunk/ext/pdo/pdo_stmt.c 2011-09-13 16:21:24 UTC (rev 316666) +++ php/php-src/trunk/ext/pdo/pdo_stmt.c 2011-09-13 16:36:29 UTC (rev 316667) @@ -1333,16 +1333,15 @@ 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 @@ 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 @@ } 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)) {

« previous php.cvs (#66509) next »