Re: GET/POST array handling (was [PATCH] Deprecate use of stdio)

From: Date: Tue, 06 May 2003 23:19:50 +0000
Subject: Re: GET/POST array handling (was [PATCH] Deprecate use of stdio)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-1326@lists.php.net to get a copy of this message
Here is an updated patch that works MUCH better and as far as I can tell works properly across all array dimensions. I am attaching the test case I've used to verify the validity of the code, as far as I can tell it appears to work fine. If there are no objection I will commit this fix prior to the next RC release, whenever it comes out. Ilia

Index: main/main.c =================================================================== RCS file: /repository/php4/main/main.c,v retrieving revision 1.512.2.25 diff -u -3 -p -r1.512.2.25 main.c --- main/main.c 28 Apr 2003 21:00:41 -0000 1.512.2.25 +++ main/main.c 6 May 2003 23:08:31 -0000 @@ -1311,6 +1311,36 @@ static inline void php_register_server_v } /* }}} */ +/* {{{ php_autoglobal_merge + */ +static void php_autoglobal_merge(HashTable *dest, HashTable *src TSRMLS_DC) +{ + zval **src_entry, **dest_entry; + char *string_key; + uint string_key_len; + ulong num_key; + HashPosition pos; + int key_type; + + zend_hash_internal_pointer_reset_ex(src, &pos); + while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) { + key_type = zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos); + if (Z_TYPE_PP(src_entry) != IS_ARRAY || (zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) != SUCCESS) || Z_TYPE_PP(dest_entry) != IS_ARRAY) { + (*src_entry)->refcount++; + if (key_type == HASH_KEY_IS_STRING) { + zend_hash_update(dest, string_key, strlen(string_key)+1, src_entry, sizeof(zval *), NULL); + } else { + zend_hash_next_index_insert(dest, src_entry, sizeof(zval *), NULL); + } + } else { + SEPARATE_ZVAL(dest_entry); + php_autoglobal_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC); + } + zend_hash_move_forward_ex(src, &pos); + } +} +/* }}} */ + /* {{{ php_hash_environment */ static int php_hash_environment(TSRMLS_D) @@ -1436,15 +1466,15 @@ static int php_hash_environment(TSRMLS_D switch (*p) { case 'g': case 'G': - zend_hash_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), (void (*)(void *pData)) zval_add_ref, NULL, sizeof(zval *), 1); + php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]) TSRMLS_CC); break; case 'p': case 'P': - zend_hash_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]), (void (*)(void *pData)) zval_add_ref, NULL, sizeof(zval *), 1); + php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]) TSRMLS_CC); break; case 'c': case 'C': - zend_hash_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), (void (*)(void *pData)) zval_add_ref, NULL, sizeof(zval *), 1); + php_autoglobal_merge(Z_ARRVAL_P(form_variables), Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) TSRMLS_CC); break; } } <form action="ex.php?person[age]=GET&a[age]=GET&b[c][G]=GET&s=123&d[1]=1&e=GET" method=post> <input type=text size=32 name="person[sname]" value="POST"> <input type=text size=32 name="a[age]" value="POST"> <input type=text size=32 name="b[c][P]" value="POST"> <input type=text size=32 name="s[arr]" value="POST"> <input type=text size=32 name="d" value="POST"> <input type=text size=32 name="e" value="POST"> <input type=submit> </form> <pre> string(3) "GPC" <br><Br> Array ( [person] => Array ( [age] => GET ) [a] => Array ( [age] => GET ) [b] => Array ( [c] => Array ( [G] => GET ) ) [s] => 123 [d] => Array ( [1] => 1 ) [e] => GET ) Array ( ) Array ( [person] => Array ( [age] => GET ) [a] => Array ( [age] => GET ) [b] => Array ( [c] => Array ( [G] => GET ) ) [s] => 123 [d] => Array ( [1] => 1 ) [e] => GET ) </pre>
« previous php.internals (#1326) next »