function processCSV(&$fileID, $willCloseResource = false, $willReturnCode = false) { // PROCESS CSV, SET VARS AND GLOBALIZE TO GLOBAL SCOPE
if ($fileID) $code = '<' . "?\n\n"; // PHP OPEN TAG
while (($data = @fgetcsv($fileID, 4096)) !== false) {
$key = $data[0];
${$key} = $data[1];
$code .= " $key = '" . str_replace("'", "\\'", ${$key}) . "';";
global ${$key};
}
if ($fileID) $code .= "\n\n?" . '>'; // PHP CLOSE TAG
if ($willCloseResource) fclose($fileID);
if ($willReturnCode) return $code;
}
For some reason, the "global ${$key}" line causes the value of $GLOBALS[$key] to literally vanish! Through using echo and print_r() statements I can easily verify that $data exists, $data[1] exists, and ${$key} exists with the value of $data[1].. until you leave the function..
Is this another case of "global doesn't global"? Please someone look at this code and tell me why this is going on, is this a "bug" or some kind of wacky issue with the "global" statement?
All I'm trying to do is to read content from a CSV file, first column is variable name, second column is its value, it sets up the variable name and sets its value, that's it.
Phil