cvs: php-src(PHP_5_2) / NEWS /ext/standard array.c basic_functions.c php_array.h /ext/standard/tests/array array_fill_keys.phpt

From: Date: Sat, 15 Jul 2006 10:21:10 +0000
Subject: cvs: php-src(PHP_5_2) / NEWS /ext/standard array.c basic_functions.c php_array.h /ext/standard/tests/array array_fill_keys.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-39249@lists.php.net to get a copy of this message
helly Sat Jul 15 10:21:10 2006 UTC Added files: (Branch: PHP_5_2) /php-src/ext/standard/tests/array array_fill_keys.phpt Modified files: /php-src NEWS /php-src/ext/standard array.c basic_functions.c php_array.h Log: - MFH Added array_fill_keys(). (Marcus, Mathew W) http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.120&r2=1.2027.2.547.2.121&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.120 php-src/NEWS:1.2027.2.547.2.121 --- php-src/NEWS:1.2027.2.547.2.120 Thu Jul 13 12:00:16 2006 +++ php-src/NEWS Sat Jul 15 10:21:09 2006 @@ -55,6 +55,7 @@ . Added readInnerXML(), readOuterXML(), readString(), setSchema(). (2.6.20+) . Changed to passing libxml options when loading reader. +- Added array_fill_keys(). (Marcus, Mathew W) - Added posix_initgroups() function. (Ilia) - Added an optional parameter to parse_url() to allow retrieval of distinct URL components. (Ilia) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.2&r2=1.308.2.21.2.3&diff_format=u Index: php-src/ext/standard/array.c diff -u php-src/ext/standard/array.c:1.308.2.21.2.2 php-src/ext/standard/array.c:1.308.2.21.2.3 --- php-src/ext/standard/array.c:1.308.2.21.2.2 Mon Jun 26 18:48:56 2006 +++ php-src/ext/standard/array.c Sat Jul 15 10:21:09 2006 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: array.c,v 1.308.2.21.2.2 2006/06/26 18:48:56 bjori Exp $ */ +/* $Id: array.c,v 1.308.2.21.2.3 2006/07/15 10:21:09 helly Exp $ */ #include "php.h" #include "php_ini.h" @@ -1720,6 +1720,56 @@ } /* }}} */ +/* {{{ proto array array_fill_keys(array keys, mixed val) + Create an array using the elements of the first parameter as keys each initialized to val */ +PHP_FUNCTION(array_fill_keys) +{ + zval **keys, **val, **entry; + HashPosition pos; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &keys, &val) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (Z_TYPE_PP(keys) != IS_ARRAY) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "First parameter must be an array"); + RETURN_FALSE; + } + + /* Initialize return array */ + array_init(return_value); + + if (!zend_hash_num_elements(Z_ARRVAL_PP(keys))) { + return; + } + + if (PZVAL_IS_REF(*val)) { + SEPARATE_ZVAL(val); + } + + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(keys), &pos); + while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(keys), (void **)&entry, &pos) == SUCCESS) { + zval_add_ref(val); + + if (Z_TYPE_PP(entry) == IS_STRING) { + zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, val, sizeof(zval *), NULL); + } else if (Z_TYPE_PP(entry) == IS_LONG) { + zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), val, sizeof(zval *), NULL); + } else { + zval tmpkey; + + tmpkey = **entry; + zval_copy_ctor(&tmpkey); + convert_to_string(&tmpkey); + + zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL(tmpkey), Z_STRLEN(tmpkey) + 1, val, sizeof(zval *), NULL); + + zval_dtor(&tmpkey); + } + zend_hash_move_forward_ex(Z_ARRVAL_PP(keys), &pos); + } +} +/* }}} */ static void array_data_shuffle(zval *array TSRMLS_DC) { http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.15&r2=1.725.2.31.2.16&diff_format=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.15 php-src/ext/standard/basic_functions.c:1.725.2.31.2.16 --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.15 Sun Jul 2 00:11:05 2006 +++ php-src/ext/standard/basic_functions.c Sat Jul 15 10:21:09 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.15 2006/07/02 00:11:05 bjori Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.16 2006/07/15 10:21:09 helly Exp $ */ #include "php.h" #include "php_streams.h" @@ -382,6 +382,12 @@ ZEND_END_ARG_INFO() static +ZEND_BEGIN_ARG_INFO(arginfo_array_fill_keys, 0) + ZEND_ARG_INFO(0, keys) /* ARRAY_INFO(0, keys, 0) */ + ZEND_ARG_INFO(0, val) +ZEND_END_ARG_INFO() + +static ZEND_BEGIN_ARG_INFO_EX(arginfo_range, 0, 0, 2) ZEND_ARG_INFO(0, low) ZEND_ARG_INFO(0, high) @@ -3672,6 +3678,7 @@ PHP_FE(extract, arginfo_extract) PHP_FE(compact, arginfo_compact) PHP_FE(array_fill, arginfo_array_fill) + PHP_FE(array_fill_keys, arginfo_array_fill_keys) PHP_FE(range, arginfo_range) PHP_FE(array_multisort, arginfo_array_multisort) PHP_FE(array_push, arginfo_array_push) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_array.h?r1=1.50.2.2.2.1&r2=1.50.2.2.2.2&diff_format=u Index: php-src/ext/standard/php_array.h diff -u php-src/ext/standard/php_array.h:1.50.2.2.2.1 php-src/ext/standard/php_array.h:1.50.2.2.2.2 --- php-src/ext/standard/php_array.h:1.50.2.2.2.1 Sat Jun 3 18:56:44 2006 +++ php-src/ext/standard/php_array.h Sat Jul 15 10:21:09 2006 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_array.h,v 1.50.2.2.2.1 2006/06/03 18:56:44 andrei Exp $ */ +/* $Id: php_array.h,v 1.50.2.2.2.2 2006/07/15 10:21:09 helly Exp $ */ #ifndef PHP_ARRAY_H #define PHP_ARRAY_H @@ -54,6 +54,7 @@ PHP_FUNCTION(extract); PHP_FUNCTION(compact); PHP_FUNCTION(array_fill); +PHP_FUNCTION(array_fill_keys); PHP_FUNCTION(range); PHP_FUNCTION(shuffle); PHP_FUNCTION(array_multisort); http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_fill_keys.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_fill_keys.phpt +++ php-src/ext/standard/tests/array/array_fill_keys.phpt --TEST-- basic array_fill_keys test --FILE-- <?php var_dump(array_fill_keys('test', 1)); var_dump(array_fill_keys(array(), 1)); var_dump(array_fill_keys(array('foo', 'bar'), NULL)); var_dump(array_fill_keys(array('5', 'foo', 10, 1.23), 123)); var_dump(array_fill_keys(array('test', TRUE, 10, 100), '')); ?> --EXPECTF-- Warning: array_fill_keys(): First parameter must be an array in %s on line %d bool(false) array(0) { } array(2) { ["foo"]=> NULL ["bar"]=> NULL } array(4) { [5]=> int(123) ["foo"]=> int(123) [10]=> int(123) ["1.23"]=> int(123) } array(4) { ["test"]=> string(0) "" [1]=> string(0) "" [10]=> string(0) "" [100]=> string(0) "" } --UEXPECTF-- Warning: array_fill_keys(): First parameter must be an array in %s on line %d bool(false) array(0) { } array(2) { [u"foo"]=> NULL [u"bar"]=> NULL } array(4) { [5]=> int(123) [u"foo"]=> int(123) [10]=> int(123) [u"1.23"]=> int(123) } array(4) { [u"test"]=> unicode(0) "" [1]=> unicode(0) "" [10]=> unicode(0) "" [100]=> unicode(0) "" }

« previous php.cvs (#39249) next »