note 12007 deleted from language.variables.predefined by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 19:24:53 +0000 |
| Subject: | note 12007 deleted from language.variables.predefined by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22650@lists.php.net to get a copy of this message | ||
[Editor's note: Variable names in PHP *cannot* have spaces, and this is clearly mentioned in
the "Variables" section of the manual, therefore the behavior you observe is a an attempt
to fix incorrectly named variables to conform w/ the expected pattern by the PHP interpreter.
The RFCs for URI/URL and CGI specs indicate that:
"... The query component is a string of information to be interpreted by the resource ..."
and thus variable naming conventions should conform to the specifications that the resource (PHP
script in this case) dictates. Scripting languages for the web support variable w/o spaces in their
names. This editor is not aware of a web scripting language in which you can use blank space in var
names, or use of different number of blank spaces in var names for differentiating between similar
named variables.]
A note about working with variables whose names have spaces:
At the current time, $HTTP_GET_VARS and $HTTP_POST_VARS munges variable names which have spaces in
them, according to an existing unresolved bug report:
http://www.php.net/bugs.php?id=6685
If you are publishing a general-use PHP script which acts on dynamic form variables, or you are
adapting a PHP script to work with another (non-PHP) program which passes along variables with
spaces in their name, you will be especially affected.
The way it munges is:
1. Any spaces at the beginning of a variable are removed, and
2. Any later spaces are replaced with underscores.
Examples for POST variables:
"My Name" becomes $HTTP_POST_VARS["My_Name"]
" My Name" also becomes $HTTP_POST_VARS["My_Name"]
Use these rules to guess what the correct variable name is you need to read. You could also use a
PHP function such as the following (its named according to the bug that makes it necessary) to
formulate the right variable name:
function munge_spaces_6685($variable_name) {
return preg_replace(array("/^ +/","/ /"), array("","_"),
$variable_name);
}
-Daniel