cvs: php-src(PHP_5_2) /ext/spl php_spl.c spl.php spl_iterators.c /ext/spl/tests spl_006.phpt

From: Date: Mon, 20 Nov 2006 19:58:01 +0000
Subject: cvs: php-src(PHP_5_2) /ext/spl php_spl.c spl.php spl_iterators.c /ext/spl/tests spl_006.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-41655@lists.php.net to get a copy of this message
helly Mon Nov 20 19:58:01 2006 UTC Added files: (Branch: PHP_5_2) /php-src/ext/spl/tests spl_006.phpt Modified files: /php-src/ext/spl php_spl.c spl.php spl_iterators.c Log: - MFH: Add new test http://cvs.php.net/viewvc.cgi/php-src/ext/spl/php_spl.c?r1=1.52.2.28.2.8&r2=1.52.2.28.2.9&diff_format=u Index: php-src/ext/spl/php_spl.c diff -u php-src/ext/spl/php_spl.c:1.52.2.28.2.8 php-src/ext/spl/php_spl.c:1.52.2.28.2.9 --- php-src/ext/spl/php_spl.c:1.52.2.28.2.8 Sat Nov 4 20:27:28 2006 +++ php-src/ext/spl/php_spl.c Mon Nov 20 19:58:01 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_spl.c,v 1.52.2.28.2.8 2006/11/04 20:27:28 helly Exp $ */ +/* $Id: php_spl.c,v 1.52.2.28.2.9 2006/11/20 19:58:01 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -647,6 +647,12 @@ /* }}} */ static +ZEND_BEGIN_ARG_INFO(arginfo_iterator_to_array, 0) + ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) + ZEND_ARG_INFO(0, use_keys) +ZEND_END_ARG_INFO(); + +static ZEND_BEGIN_ARG_INFO(arginfo_iterator, 0) ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) ZEND_END_ARG_INFO(); @@ -672,7 +678,7 @@ PHP_FE(class_implements, NULL) PHP_FE(spl_object_hash, NULL) #ifdef SPL_ITERATORS_H - PHP_FE(iterator_to_array, arginfo_iterator) + PHP_FE(iterator_to_array, arginfo_iterator_to_array) PHP_FE(iterator_count, arginfo_iterator) PHP_FE(iterator_apply, arginfo_iterator_apply) #endif /* SPL_ITERATORS_H */ http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl.php?r1=1.49.2.11.2.3&r2=1.49.2.11.2.4&diff_format=u Index: php-src/ext/spl/spl.php diff -u php-src/ext/spl/spl.php:1.49.2.11.2.3 php-src/ext/spl/spl.php:1.49.2.11.2.4 --- php-src/ext/spl/spl.php:1.49.2.11.2.3 Sun Aug 13 10:37:57 2006 +++ php-src/ext/spl/spl.php Mon Nov 20 19:58:01 2006 @@ -229,9 +229,10 @@ * @since PHP 5.1 * * @param it iterator to copy + * @param use_keys whether touse the keys * @return array with elements copied from the iterator */ -function iterator_to_array(Traversable $it) {/**/}; +function iterator_to_array(Traversable $it, $use_keys = true) {/**/}; /** @ingroup ZendEngine * @brief Basic Exception class. http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_iterators.c?r1=1.73.2.30.2.20&r2=1.73.2.30.2.21&diff_format=u Index: php-src/ext/spl/spl_iterators.c diff -u php-src/ext/spl/spl_iterators.c:1.73.2.30.2.20 php-src/ext/spl/spl_iterators.c:1.73.2.30.2.21 --- php-src/ext/spl/spl_iterators.c:1.73.2.30.2.20 Tue Nov 7 15:19:11 2006 +++ php-src/ext/spl/spl_iterators.c Mon Nov 20 19:58:01 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_iterators.c,v 1.73.2.30.2.20 2006/11/07 15:19:11 johannes Exp $ */ +/* $Id: spl_iterators.c,v 1.73.2.30.2.21 2006/11/20 19:58:01 helly Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -2734,23 +2734,38 @@ } /* }}} */ -/* {{{ proto array iterator_to_array(Traversable it) +static int spl_iterator_to_values_apply(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ */ +{ + zval **data, *return_value = (zval*)puser; + + iter->funcs->get_current_data(iter, &data TSRMLS_CC); + if (EG(exception)) { + return ZEND_HASH_APPLY_STOP; + } + (*data)->refcount++; + add_next_index_zval(return_value, *data); + return ZEND_HASH_APPLY_KEEP; +} +/* }}} */ + +/* {{{ proto array iterator_to_array(Traversable it [, bool use_keys = true]) Copy the iterator into an array */ PHP_FUNCTION(iterator_to_array) { zval *obj; + zend_bool use_keys = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &obj, zend_ce_traversable) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &obj, zend_ce_traversable, &use_keys) == FAILURE) { RETURN_FALSE; } array_init(return_value); - - if (spl_iterator_apply(obj, spl_iterator_to_array_apply, (void*)return_value TSRMLS_CC) != SUCCESS) { + + if (spl_iterator_apply(obj, use_keys ? spl_iterator_to_array_apply : spl_iterator_to_values_apply, (void*)return_value TSRMLS_CC) != SUCCESS) { zval_dtor(return_value); RETURN_NULL(); } -} +} /* }}} */ static int spl_iterator_count_apply(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ */ { http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/spl_006.phpt?view=markup&rev=1.1 Index: php-src/ext/spl/tests/spl_006.phpt +++ php-src/ext/spl/tests/spl_006.phpt --TEST-- SPL: iterator_to_array() without keys --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- <?php $it = new AppendIterator(); $it->append(new ArrayIterator(array(1,2))); $it->append(new ArrayIterator(array(2,3))); var_dump(iterator_to_array($it)); var_dump(iterator_to_array($it, false)); var_dump(iterator_to_array($it, true)); ?> ===DONE=== --EXPECT-- array(2) { [0]=> int(2) [1]=> int(3) } array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(2) [3]=> int(3) } array(2) { [0]=> int(2) [1]=> int(3) } ===DONE===

« previous php.cvs (#41655) next »