|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-10-01 07:49 UTC] ross dot w at paradise dot net dot nz
Description: ------------ The $_POST variable does not return an array (eg. from a select multiple box) but instead returns the word "Array". $HTTP_POST_VARS and register globals do not have this problem. Reproduce code: --------------- <select multiple="multiple" name="test[]"> <option name="o1">Option 1</option> <option name="o2">Option 2</option> <option name="o3">Option 3</option> </select> User selects some of these and clicks Submit Expected result: ---------------- I would expect that these three cases should be equal on the PHP receiving side: $arr = $_POST["test"]; $arr = $HTTP_POST_VARS["test"]; $arr = $test; (On systems with register globals) Actual result: -------------- Instead: $arr = $_POST["test"]; $arr is a string with the word "Array" (incorrect) $arr = $HTTP_POST_VARS["test"]; $arr is the array of selected items (correct) $arr = $test; On systems with register globals, $arr is the array of selected items (correct) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 UTC |
After trying to find the problem I was unable to produce the problem without my usual includes, which includes stripping slashes from the $_POST variable. Indeed when I made a script with this one function (below) it had the same behaviour. I'm now no longer sure this is a bug, apologies for wasting your time. Here's the script, for reference: <?php $_POST = array_map('stripslashes',$_POST); if (!isset($HTTP_POST_VARS["test"])) { echo '<form action="'.$_SERVER["PHP_SELF"].'?hai=hai" method="post"><select multiple="multiple" size="5" name="test[]"><option name="o1">Option 1</option><option name="o2">Option 2</option><option name="o3">Option 3</option></select><br /><input type="submit" value="Go"></form>'; } else { echo 'These should all be identical<br />$_POST:<br />'; print_r($_POST["test"]); echo '<br />$HTTP_POST_VARS:<br />'; print_r($HTTP_POST_VARS["test"]); echo '<br />register globals:<br />'; print_r($test); } ?>