tony2001                Tue Aug 22 19:55:56 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/standard       string.c 
  Log:
  fix implode() function (see http://news.php.net/php.qa/26876)
  add test
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.11&r2=1.445.2.14.2.12&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.445.2.14.2.11 
php-src/ext/standard/string.c:1.445.2.14.2.12
--- php-src/ext/standard/string.c:1.445.2.14.2.11       Thu Aug 10 14:40:12 2006
+++ php-src/ext/standard/string.c       Tue Aug 22 19:55:56 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.445.2.14.2.11 2006/08/10 14:40:12 iliaa Exp $ */
+/* $Id: string.c,v 1.445.2.14.2.12 2006/08/22 19:55:56 tony2001 Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -886,6 +886,10 @@
        HashPosition   pos;
        smart_str      implstr = {0};
        int            numelems, i = 0;
+       zend_bool free_tmp_val;
+       zval tmp_val;
+       char *str;
+       int str_len;
 
        numelems = zend_hash_num_elements(Z_ARRVAL_P(arr));
 
@@ -896,6 +900,7 @@
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
 
        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) &tmp, 
&pos) == SUCCESS) {
+               free_tmp_val = 0;
                if ((*tmp)->type != IS_STRING) {
                        if ((*tmp)->type == IS_OBJECT) {
                                int copy;
@@ -907,12 +912,23 @@
                                }
                                goto next;
                        } else {
-                               SEPARATE_ZVAL(tmp);
-                               convert_to_string(*tmp);
+                               tmp_val = **tmp;
+                               zval_copy_ctor(&tmp_val);
+                               convert_to_string(&tmp_val);
+                               str = Z_STRVAL(tmp_val);
+                               str_len = Z_STRLEN(tmp_val);
+                               free_tmp_val = 1;
                        }
-               } 
+               } else {
+                       str = Z_STRVAL_PP(tmp);
+                       str_len = Z_STRLEN_PP(tmp);
+               }
                
-               smart_str_appendl(&implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
+               smart_str_appendl(&implstr, str, str_len);
+
+               if (free_tmp_val) {
+                       zval_dtor(&tmp_val);
+               }
 next:
                if (++i != numelems) {
                        smart_str_appendl(&implstr, Z_STRVAL_P(delim), 
Z_STRLEN_P(delim));

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

Reply via email to