note 46611 deleted from function.compact by tomsommer
| From: | tomsommer@php.net | Date: | Sun, 17 Oct 2004 15:17:46 +0000 |
| Subject: | note 46611 deleted from function.compact by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78699@lists.php.net to get a copy of this message | ||
Note Submitter: rwruck
----
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();
?>