note 48857 added to function.import-request-variables
| From: | cornflake4 at gmx dot at | Date: | Sun, 09 Jan 2005 17:39:30 +0000 |
| Subject: | note 48857 added to function.import-request-variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83000@lists.php.net to get a copy of this message | ||
Beware:
import_request_variables() does not copy the request variables into local scope variables. Instead,
it copies the *reference* to the request variable content to local variables Important implication:
any change to the local variable means a changes to the respective request variable, too!
This is a clear difference to extract($_GET) which copies the content of the request variables into
local variables.
To shed some light on the implication, consider this (assuming the query string
"...&var=1"):
echo $_GET['var']; # prints: 1
import_request_variables();
echo $var; # prints 1
$var = 2;
echo $_GET['var']; # prints 2 !!!!
So, $_GET has changed as well!
On the other hand:
echo $_GET['var']; # prints: 1
extract($_GET);
echo $var; # prints 1
$var = 2;
echo $_GET['var']; # prints 2 !!!!
Because of this, I recommend NOT using import_request_variables(), but extract($_GET);
extract($_POST); extract($_COOKIE); instead, since this combination bears not these unexspected side
effects.
PS: not to mention that you have to reconsider your coding style if any need to
import_request_variables arises at all!
----
Manual Page -- http://www.php.net/manual/en/function.import-request-variables.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48857
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48857&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48857&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48857&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48857&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48857&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48857&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48857&report=yes
Search -- http://master.php.net/manage/user-notes.php