#27572 [NEW]: Allowing characters other than [] to define arrays in POST or GET variables

From: Date: Thu, 11 Mar 2004 17:05:30 +0000
Subject: #27572 [NEW]: Allowing characters other than [] to define arrays in POST or GET variables
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56328@lists.php.net to get a copy of this message
From: marwan at marvonline dot org Operating system: Any PHP version: Irrelevant PHP Bug Type: Feature/Change Request Bug description: Allowing characters other than [] to define arrays in POST or GET variables Description: ------------ PHP registers HTML variables that look like arrays as array variables, which is pretty convenient for packaging form variables. I'm building a form generator that utilizes this feature a lot. It uses it something like this: for ($i=0; $i<count($data['ID']); $i++) { echo "<input type=\"hidden\" name=\"data[ID][$i]\" value=\"{$data['ID'][$i]}\"> " ."<input type=\"text\" name=\"data[Name][$i]\" value=\"{$data['Name'][$i]\"><br>\n"; } The (slightly) annoying thing about this is that urlencoding the variable names replaces the '[' and ']' with three letter codes. If the arrays are large (as they typically are) this bloats the POST request quite a lot. If PHP would consider the '.' as an array operator when registering GET and POST variables, it would improve matters. The '.' is urlencoded as a '.' with no charcter inflation. Further, it would only require one operator instead of two ([ and ]). The code would then look like: for ($i=0; $i<count($data['ID']); $i++) { echo "<input type=\"hidden\" name=\"data.ID.$i\" value=\"{$data['ID'][$i]}\"> " ."<input type=\"text\" name=\"data.Name.$i\" value=\"{$data['Name'][$i]\"><br>\n"; } Since PHP forbids using the '.' in variable names anyway, this shouldn't affect much code. To be safe, an INI option could be made to switch this behaviour on and off. As far as I can tell, the only function that would need to change would be php_register_variable_ex in main/php_variables.c I would be quite willing to re-code the function and hand it to someone who has CVS access. -- Edit bug report at http://bugs.php.net/?id=27572&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27572&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27572&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=27572&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=27572&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=27572&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=27572&r=needscript Try newer version: http://bugs.php.net/fix.php?id=27572&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=27572&r=support Expected behavior: http://bugs.php.net/fix.php?id=27572&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=27572&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=27572&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=27572&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27572&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=27572&r=dst IIS Stability: http://bugs.php.net/fix.php?id=27572&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=27572&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=27572&r=float

« previous php.bugs (#56328) next »