note 46612 added to function.extract
| From: | rwruck at osu1 dot php dot net | Date: | Sun, 17 Oct 2004 13:22:29 +0000 |
| Subject: | note 46612 added to function.extract | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78694@lists.php.net to get a copy of this message | ||
It should be noted that extract() and compact() don't work with superglobals inside of
functions.
<?php
// Works:
$saved = compact('_SERVER');
echo count($saved); // prints '1'
$_SERVER['HTTP_HOST'] = 'garbage';
extract($saved);
echo $_SERVER['HTTP_HOST']; // prints the original server name
// ... but:
function tester()
{
$saved = compact('_SERVER');
echo count($saved); // prints '0'
$saved['_SERVER'] = $_SERVER;
echo count($saved); // prints '1'
$_SERVER['HTTP_HOST'] = 'garbage';
extract($saved);
echo $_SERVER['HTTP_HOST']; // prints 'garbage'
$_SERVER = $saved['_SERVER'];
echo $_SERVER['HTTP_HOST']; // prints the original server name
}
tester();
?>
----
Manual Page -- http://www.php.net/manual/en/function.extract.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46612
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46612&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46612&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46612&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46612&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46612&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46612&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46612&report=yes
Search -- http://master.php.net/manage/user-notes.php