php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40000 dots and spaces in variable names are replaced with underscore in $_GET
Submitted: 2007-01-02 13:51 UTC Modified: 2007-04-08 12:48 UTC
Votes:20
Avg. Score:4.1 ± 0.9
Reproduced:18 of 19 (94.7%)
Same Version:1 (5.6%)
Same OS:5 (27.8%)
From: bertrand at epistema dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.4.4 OS: linux debian
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-01-02 13:51 UTC] bertrand at epistema dot com
Description:
------------
Can someone please add more information to bug 34578 ?

The only two places in the documentation that refers to the fact that PHP replaces dots with underscores in variable names are http://fr.php.net/manual/en/language.variables.predefined.php#64336 and http://fr.php.net/manual/en/language.variables.external.php but doesn't really help on the why of this behaviour...

Are dots not valid in variable names ? Since when ?

Reproduce code:
---------------
<?php

echo '<pre>what : <br>' . print_r($_GET, true) . '</pre><br>';

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="GET">
<input type="hidden" name="test.one" value="1" />
<input type="hidden" name="test.two" value="2" />
<input type="submit" name="submitMe" value="Click me" />
</form>

</body>
</html>


Expected result:
----------------
Array
(
    [test.one] => 1
    [test.two] => 2
    [submitMe] => Click me
)

Actual result:
--------------
Array
(
    [test_one] => 1
    [test_two] => 2
    [submitMe] => Click me
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-02 13:55 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

This has been filed many times... and it\'s not a bug.
 [2007-01-02 15:23 UTC] bertrand at epistema dot com
Derick, thanks for reviewing this bug.

After quite a lot of searching, I found the reason why: it all comes from the old "register globals" days. Obviously, a variable named $test.one would not be valid.

Now, those variables are valid in a form (and in a URL), as stated here:

http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-cdata

Quote : ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Therefore, one could think that since it fits in the $_POST array without problem, the underscoring of dots and spaces could only be done when registring the globals by their names, but not in the $_POST and $_GET variables.

In other words, if taking the example, that could give:

$test_one => 1
$test.two => 2

but also:
 
$_POST['test.one'] => 1
$_POST['test.two'] => 2

I still consider this to be a bug, since this behaviour is *not documented* nor logical (in the case you use $_POST and $_GET variables and not register_globals, as everybody does).
 [2007-04-08 12:48 UTC] derick@php.net
Yes, but changing this breaks BC unnecessarily, so we won't change it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC