Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PHP replaces . with an underscore if it's a key in $_GET? [duplicate]

Tags:

php

Possible Duplicate:
PHP replaces spaces with underlines

Example: test.php?foo.bar=1

print_r($_GET);

// Array ( [foo_bar] => 1 ) 
like image 655
IMB Avatar asked Dec 21 '22 07:12

IMB


2 Answers

Here is a quote from PHP manual

Dots in incoming variable names

Typically, PHP does not alter the names of variables when they are passed into a script. However, it should be noted that the dot (period, full stop) is not a valid character in a PHP variable name. For the reason, look at it:

<?php $varname.ext;  /* invalid variable name */ ?> Now, what the

parser sees is a variable named $varname, followed by the string concatenation operator, followed by the barestring (i.e. unquoted string which doesn't match any known key or reserved words) 'ext'. Obviously, this doesn't have the intended result. For this reason, it is important to note that PHP will automatically replace any dots in incoming variable names with underscores.

like image 135
hsz Avatar answered Dec 23 '22 21:12

hsz


if the register_globals directive is set, array keys in $_GET must be used as variable names and dots, spaces as well as a variety of other characters aren't allowed in php variable names. In fear that you have that directive set, php replaces those 'invalid' characters

like image 40
uncreative Avatar answered Dec 23 '22 22:12

uncreative