helly           Sat Jul 15 12:14:07 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src    NEWS 
    /php-src/ext/standard       array.c 
    /php-src/ext/standard/tests/array   array_fill_keys.phpt 
  Log:
  - MFH array_fill_keys, better unicode support, use new param parsing API
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.121&r2=1.2027.2.547.2.122&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.121 php-src/NEWS:1.2027.2.547.2.122
--- php-src/NEWS:1.2027.2.547.2.121     Sat Jul 15 10:21:09 2006
+++ php-src/NEWS        Sat Jul 15 12:14:07 2006
@@ -55,7 +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 array_fill_keys(). (Marcus, Matthew Wilmas)
 - 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.3&r2=1.308.2.21.2.4&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.308.2.21.2.3 
php-src/ext/standard/array.c:1.308.2.21.2.4
--- php-src/ext/standard/array.c:1.308.2.21.2.3 Sat Jul 15 10:21:09 2006
+++ php-src/ext/standard/array.c        Sat Jul 15 12:14:07 2006
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: array.c,v 1.308.2.21.2.3 2006/07/15 10:21:09 helly Exp $ */
+/* $Id: array.c,v 1.308.2.21.2.4 2006/07/15 12:14:07 helly Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -1579,6 +1579,49 @@
 }
 /* }}} */
 
+/* {{{ 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_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "az", &keys, &val) 
== FAILURE) {
+               return;
+       }
+
+       /* Initialize return array */
+       array_init(return_value);
+
+       zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(keys), &pos);
+       while (zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), (void **)&entry, 
&pos) == SUCCESS) {
+
+               if (Z_TYPE_PP(entry) == IS_LONG) {
+                       zval_add_ref(&val);
+                       zend_hash_index_update(Z_ARRVAL_P(return_value), 
Z_LVAL_PP(entry), &val, sizeof(zval *), NULL);
+               } else {
+                       zval key, *key_ptr = *entry;
+
+                       if (Z_TYPE_PP(entry) != IS_STRING) {
+                               key = **entry;
+                               zval_copy_ctor(&key);
+                               convert_to_string(&key);
+                               key_ptr = &key;
+                       }
+
+                       zval_add_ref(&val);
+                       zend_symtable_update(Z_ARRVAL_P(return_value), 
Z_STRVAL_P(key_ptr), Z_STRLEN_P(key_ptr) + 1, &val, sizeof(zval *), NULL);
+
+                       if (key_ptr != *entry) {
+                               zval_dtor(&key);
+                       }
+               }
+
+               zend_hash_move_forward_ex(Z_ARRVAL_P(keys), &pos);
+       }
+}
+/* }}} */
+
 /* {{{ proto array range(mixed low, mixed high[, int step])
    Create an array containing the range of integers or characters from low to 
high (inclusive) */
 PHP_FUNCTION(range)
@@ -1720,57 +1763,6 @@
 }
 /* }}} */
 
-/* {{{ 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)
 {
        Bucket **elems, *temp;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_fill_keys.phpt?r1=1.1.2.2&r2=1.1.2.3&diff_format=u
Index: php-src/ext/standard/tests/array/array_fill_keys.phpt
diff -u php-src/ext/standard/tests/array/array_fill_keys.phpt:1.1.2.2 
php-src/ext/standard/tests/array/array_fill_keys.phpt:1.1.2.3
--- php-src/ext/standard/tests/array/array_fill_keys.phpt:1.1.2.2       Sat Jul 
15 10:21:10 2006
+++ php-src/ext/standard/tests/array/array_fill_keys.phpt       Sat Jul 15 
12:14:07 2006
@@ -10,8 +10,8 @@
 ?>
 --EXPECTF--
 
-Warning: array_fill_keys(): First parameter must be an array in %s on line %d
-bool(false)
+Warning: array_fill_keys() expects parameter 1 to be array, string given in %s 
on line %d
+NULL
 array(0) {
 }
 array(2) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to