diff -rc php-4.0.2/ext/standard/basic_functions.c php-4.0.2-ds/ext/standard/basic_functions.c
*** php-4.0.2/ext/standard/basic_functions.c	Sun Aug 27 18:46:40 2000
--- php-4.0.2-ds/ext/standard/basic_functions.c	Tue Sep  5 11:51:31 2000
***************
*** 173,179 ****
  	PHP_FE(levenshtein,									NULL)
  	PHP_FE(chr,										NULL)
  	PHP_FE(ord,										NULL)
! 	PHP_FE(parse_str,								NULL)
  	PHP_FE(str_pad,									NULL)
  	PHP_FALIAS(rtrim,			chop,				NULL)
  	PHP_FALIAS(strchr,			strstr,				NULL)
--- 173,179 ----
  	PHP_FE(levenshtein,									NULL)
  	PHP_FE(chr,										NULL)
  	PHP_FE(ord,										NULL)
! 	PHP_FE(parse_str,								second_arg_force_ref)
  	PHP_FE(str_pad,									NULL)
  	PHP_FALIAS(rtrim,			chop,				NULL)
  	PHP_FALIAS(strchr,			strstr,				NULL)

diff -rc php-4.0.2/ext/standard/string.c php-4.0.2-ds/ext/standard/string.c
*** php-4.0.2/ext/standard/string.c	Fri Aug 18 09:43:22 2000
--- php-4.0.2-ds/ext/standard/string.c	Tue Sep  5 11:46:14 2000
***************
*** 2331,2348 ****
  PHP_FUNCTION(parse_str)
  {
  	zval **arg;
  	char *res = NULL;
  	PLS_FETCH();
  	SLS_FETCH();
  
! 	if (zend_get_parameters_ex(1, &arg) == FAILURE) {
  		WRONG_PARAM_COUNT;
  	}
  	convert_to_string_ex(arg);
! 	if ((*arg)->value.str.val && *(*arg)->value.str.val) {
! 		res = estrndup((*arg)->value.str.val,(*arg)->value.str.len);
  	}
- 	php_treat_data(PARSE_STRING, res ELS_CC PLS_CC SLS_CC);
  }
  /* }}} */
  
--- 2331,2370 ----
  PHP_FUNCTION(parse_str)
  {
  	zval **arg;
+ 	zval **arrayArg;
+ 	zval *sarg;
  	char *res = NULL;
+ 	int argCount;
+ 	
  	PLS_FETCH();
  	SLS_FETCH();
  
! 	argCount = ARG_COUNT(ht);
! 	if(argCount < 1 || argCount > 2 || zend_get_parameters_ex(argCount, &arg, &arrayArg) == FAILURE) {
  		WRONG_PARAM_COUNT;
  	}
+ 
  	convert_to_string_ex(arg);
! 	sarg = *arg;
! 	if (sarg->value.str.val && *sarg->value.str.val) {
! 		res = estrndup(sarg->value.str.val, sarg->value.str.len);
! 	}
! 
! 	if(argCount == 1)
! 		php_treat_data(PARSE_STRING, res, NULL ELS_CC PLS_CC SLS_CC);
! 	else
! 	{
! 		if(!ParameterPassedByReference(ht, 2)){
! 			php3_error(E_WARNING, "Array not passed by reference in call to parse_str()");
! 			return;
! 		}
! 		
! 		//Clear out the array that was passed in.
! 		pval_destructor(*arrayArg);
! 		array_init(*arrayArg);
! 		
! 		php_treat_data(PARSE_STRING, res, arrayArg ELS_CC PLS_CC SLS_CC);
  	}
  }
  /* }}} */
  
diff -rc php-4.0.2/main/main.c php-4.0.2-ds/main/main.c
*** php-4.0.2/main/main.c	Tue Aug 29 05:18:48 2000
--- php-4.0.2-ds/main/main.c	Tue Sep  5 11:45:29 2000
***************
*** 973,993 ****
  			case 'p':
  			case 'P':
  				if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) {
! 					php_treat_data(PARSE_POST, NULL ELS_CC PLS_CC SLS_CC);	/* POST Data */
  					_gpc_flags[0]=1;
  				}
  				break;
  			case 'c':
  			case 'C':
  				if (!_gpc_flags[1]) {
! 					php_treat_data(PARSE_COOKIE, NULL ELS_CC PLS_CC SLS_CC);	/* Cookie Data */
  					_gpc_flags[1]=1;
  				}
  				break;
  			case 'g':
  			case 'G':
  				if (!_gpc_flags[2]) {
! 					php_treat_data(PARSE_GET, NULL ELS_CC PLS_CC SLS_CC);	/* GET Data */
  					_gpc_flags[2]=1;
  				}
  				break;
--- 973,993 ----
  			case 'p':
  			case 'P':
  				if (!_gpc_flags[0] && !SG(headers_sent) && SG(request_info).request_method && !strcasecmp(SG(request_info).request_method, "POST")) {
! 					php_treat_data(PARSE_POST, NULL, NULL ELS_CC PLS_CC SLS_CC);	/* POST Data */
  					_gpc_flags[0]=1;
  				}
  				break;
  			case 'c':
  			case 'C':
  				if (!_gpc_flags[1]) {
! 					php_treat_data(PARSE_COOKIE, NULL, NULL  ELS_CC PLS_CC SLS_CC);	/* Cookie Data */
  					_gpc_flags[1]=1;
  				}
  				break;
  			case 'g':
  			case 'G':
  				if (!_gpc_flags[2]) {
! 					php_treat_data(PARSE_GET, NULL, NULL  ELS_CC PLS_CC SLS_CC);	/* GET Data */
  					_gpc_flags[2]=1;
  				}
  				break;

diff -rc php-4.0.2/main/php_variables.c php-4.0.2-ds/main/php_variables.c
*** php-4.0.2/main/php_variables.c	Mon Aug 21 05:50:53 2000
--- php-4.0.2-ds/main/php_variables.c	Tue Sep  5 11:45:04 2000
***************
*** 209,215 ****
  }
  
  
! void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC)
  {
  	char *res = NULL, *var, *val;
  	pval *array_ptr;
--- 209,215 ----
  }
  
  
! void php_treat_data(int arg, char *str, zval** destArray ELS_DC PLS_DC SLS_DC)
  {
  	char *res = NULL, *var, *val;
  	pval *array_ptr;
***************
*** 289,295 ****
  			/* FIXME: XXX: not binary safe, discards returned length */
  			php_url_decode(var, strlen(var));
  			php_url_decode(val, strlen(val));
! 			php_register_variable(var, val, array_ptr ELS_CC PLS_CC);
  		}
  		if (arg == PARSE_COOKIE) {
  			var = php_strtok_r(NULL, ";", &strtok_buf);
--- 289,299 ----
  			/* FIXME: XXX: not binary safe, discards returned length */
  			php_url_decode(var, strlen(var));
  			php_url_decode(val, strlen(val));
! 			
! 			if(!destArray)
! 				php_register_variable(var, val, array_ptr ELS_CC PLS_CC);
! 			else
! 				add_assoc_string(*destArray, var, val, 1);
  		}
  		if (arg == PARSE_COOKIE) {
  			var = php_strtok_r(NULL, ";", &strtok_buf);
diff -rc php-4.0.2/main/php_variables.h php-4.0.2-ds/main/php_variables.h
*** php-4.0.2/main/php_variables.h	Sun Jul 23 21:39:51 2000
--- php-4.0.2-ds/main/php_variables.h	Tue Sep  5 11:44:19 2000
***************
*** 30,36 ****
  #define PARSE_COOKIE 2
  #define PARSE_STRING 3
  
! void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC);
  void php_import_environment_variables(ELS_D PLS_DC);
  PHPAPI void php_register_variable(char *var, char *val, pval *track_vars_array ELS_DC PLS_DC);
  PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array ELS_DC PLS_DC);
--- 30,36 ----
  #define PARSE_COOKIE 2
  #define PARSE_STRING 3
  
! void php_treat_data(int arg, char *str, zval** destArray ELS_DC PLS_DC SLS_DC);
  void php_import_environment_variables(ELS_D PLS_DC);
  PHPAPI void php_register_variable(char *var, char *val, pval *track_vars_array ELS_DC PLS_DC);
  PHPAPI void php_register_variable_ex(char *var, zval *val, pval *track_vars_array ELS_DC PLS_DC);

