PHP 4.0 Bug #5768 Updated: patch to make parse_str() optionally save into an array
| From: | Bug Database | Date: | Fri, 29 Sep 2000 18:56:56 +0000 |
| Subject: | PHP 4.0 Bug #5768 Updated: patch to make parse_str() optionally save into an array | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-33861@lists.php.net to get a copy of this message | ||
ID: 5768
Updated by: waldschrott
Reported By: dshadow@zort.net
Status: Closed
Bug Type: Feature/Change Request
Assigned To:
Comments:
fixed
Previous Comments:
---------------------------------------------------------------------------
[2000-07-24 23:37:34] dshadow@zort.net
The following patch modifies parse_str() to optionally save variables into an array, rather than
into the current variable space.
Usage:
Normal:
parse_str(encodedString);
Saves variables into the output array, rather than into the current variable space:
parse_str(encodedString, outputArray);
This has been used in a production environment for at least six months with no problems. (The patch
was originally written for PHP3.) I'm hoping this can get included with PHP so I don't
have to keep repatching whenever a new PHP version is released.
John Bafford
dshadow@zort.net
--
*** string.old Mon Jul 24 17:14:32 2000
--- string.c Mon Jul 24 17:16:23 2000
***************
*** 2162,2184 ****
}
/* }}} */
! /* {{{ proto void parse_str(string encoded_string)
! Parses GET/POST/COOKIE data and sets global variables. */
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);
}
/* }}} */
--- 2162,2227 ----
}
/* }}} */
! /* {{{ proto void parse_str(string encoded_string, [array storage])
! Parses GET/POST/COOKIE data and sets global variables.
! Stores into storage if array is given
! */
PHP_FUNCTION(parse_str)
{
! zval **arg, **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 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);
!
! if(res) //hacked up php_treat_data
! {
! char *var, *val;
!
! var = strtok(res, PG(arg_separator));
!
! while (var) {
! val = strchr(var, '=');
! if (val) { /* have a value */
! *val++ = '