sterling                Fri Oct  4 12:53:14 2002 EDT

  Modified files:              
    /php4/ext/standard  string.c 
  Log:
  @ Make the glue argument to implode() optional, if it is not specified 
  @ default to using "". (Sterling)
  
  
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.308 php4/ext/standard/string.c:1.309
--- php4/ext/standard/string.c:1.308    Thu Oct  3 14:15:18 2002
+++ php4/ext/standard/string.c  Fri Oct  4 12:53:14 2002
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.308 2002/10/03 18:15:18 andrey Exp $ */
+/* $Id: string.c,v 1.309 2002/10/04 16:53:14 sterling Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -857,30 +857,45 @@
 }
 /* }}} */
 
-/* {{{ proto string implode(string glue, array pieces)
+/* {{{ proto string implode([string glue,] array pieces)
    Joins array elements placing glue string between items and return one string */
 PHP_FUNCTION(implode)
 {
-       zval **arg1, **arg2, *delim, *arr;
-       
-       if (ZEND_NUM_ARGS() != 2 || 
-               zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
+       zval **arg1 = NULL, **arg2 = NULL, *delim, *arr;
+       int argc = ZEND_NUM_ARGS();
+
+       if (argc < 1 || argc > 2 ||
+               zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
 
-       if (Z_TYPE_PP(arg1) == IS_ARRAY) {
+       if (argc == 1) {
+               MAKE_STD_ZVAL(delim);
+#define _IMPL_EMPTY ""
+               ZVAL_STRINGL(delim, _IMPL_EMPTY, sizeof(_IMPL_EMPTY) - 1, 0);
+
+               if (Z_TYPE_PP(arg1) != IS_ARRAY) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument to 
+implode must be an array");
+                       return;
+               }
+
                SEPARATE_ZVAL(arg1);
                arr = *arg1;
-               convert_to_string_ex(arg2);
-               delim = *arg2;
-       } else if (Z_TYPE_PP(arg2) == IS_ARRAY) {
-               SEPARATE_ZVAL(arg2)
-               arr = *arg2;
-               convert_to_string_ex(arg1);
-               delim = *arg1;
        } else {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad arguments.");
-               return;
+               if (Z_TYPE_PP(arg1) == IS_ARRAY) {
+                       SEPARATE_ZVAL(arg1);
+                       arr = *arg1;
+                       convert_to_string_ex(arg2);
+                       delim = *arg2;
+               } else if (Z_TYPE_PP(arg2) == IS_ARRAY) {
+                       SEPARATE_ZVAL(arg2);
+                       arr = *arg2;
+                       convert_to_string_ex(arg1);
+                       delim = *arg1;
+               } else {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad arguments.");
+                       return;
+               }
        }
 
        php_implode(delim, arr, return_value);



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

Reply via email to