note 43191 deleted from function.eval by danbrown
| From: | danbrown@php.net | Date: | Tue, 25 Nov 2008 16:10:11 +0000 |
| Subject: | note 43191 deleted from function.eval by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146950@lists.php.net to get a copy of this message | ||
Note Submitter: info [at] derosetechnologies [dot] com
----
"Bart Koelman" 's example above (OutputPhpDocument), though thouroughly functional
, would benefit by using the "extract()" function in lieu of his variable exporting
solution. I.e.:
<?
reset ($GLOBALS);
while (list ($key, $val) = each ($GLOBALS))
{
eval("\$" . "\$key = \"$val\";");
}
?>
Can be replaced with a single line:
<?extract($GLOBALS, EXTR_SKIP | EXTR_REFS);?>
Addtionally, this latter alternative will load the global variables as references instead of
'copies'. (Meaning that if a value is altered inside the function , that modification
will also be effected outside of the OutputPhpDocument() function.