#40224 [WFx]: Could PHP leave superglobal array indices alone?

From: Date: Wed, 02 Jan 2008 15:02:59 +0000
Subject: #40224 [WFx]: Could PHP leave superglobal array indices alone?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120987@lists.php.net to get a copy of this message
ID: 40224 User updated by: joem at tempomg dot com Reported By: joem at tempomg dot com Status: Wont fix Bug Type: Feature/Change Request Operating System: redhat linux PHP Version: 5.2.0 New Comment: If, aside from backward compatibility, there are no disadvantages to fixing this bug, wouldn't it be easy enough to have both versions of the variable in the superglobal array to make the fix backward compatible? Also, in response to Michael: right, the sample code is not real life code obviously :) The reason I am using variable names with spaces and periods is that the variable names are autogenerated based on page titles and filenames. I figured out a way around it easily enough - after I figured out what was happening. But it took me a while to figure it out with the documentation not mentioning it! I just think if there's no reason not to, it would sure make things easier to keep the indices unaltered whenever possible. Previous Comments: ------------------------------------------------------------------------ [2008-01-01 16:24:12] johannes@php.net This can't be fixed without breaking application relying on that feature. ------------------------------------------------------------------------ [2007-12-31 23:15:31] michael at chunkycow dot com dot au G'day Why dont you just call it 'title' then: <? if(!empty($_POST['title'])) echo $_POST['title']; ?> you can even make them an array eg. <form method="post"> <input name="title[]" type="text"> <input type="submit"> </form> <? if( (!empty($_POST['title'])) && is_array($_POST['title'])) { foreach($_POST['title'] AS $title) echo $title,'<br>'; } ?> You should be escaping the output for real life code but I'm sure you knew that ;) ------------------------------------------------------------------------ [2007-01-24 20:09:32] joem at tempomg dot com Description: ------------ I think it would make more sense if PHP only replaced '.' and ' ' with '_' when register_globals is turned on, and only for the variables that are registered in the global scope, leaving the superglobals' index names as they are. I understand that variable names can't have '.' or ' ' in them, however it seems that most people use the $_POST['variablename'] method of accessing external variables, and in this case, the spaces and dots make no difference. I could find practically no reference to this behavior in the manual, other than a couple notes I submitted. At the very least, the fact that these characters are replaced should be made more obvious in the manual under "Predefined Variables" at http://us2.php.net/manual/en/language.variables.predefined.php and http://us2.php.net/manual/en/reserved.variables.php Reproduce code: --------------- <form method="post"> <input name="title for page3.php" type="text"> <input type="submit"> </form> Title submitted: <?php if (count($_POST) > 0) echo $_POST['title for page3.php']; ?> Expected result: ---------------- I expect to see the title I submitted print out. Actual result: -------------- The POST key 'title for page3.php' is changed to 'title_for_page3_php', and nothing prints out. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40224&edit=1

« previous php.bugs (#120987) next »