I'm creating a function that I want to "import" a variable from global scope and I want to modify this variable. I do NOT want to save these modifications to the global variable, but only within the function.
The only way I know to do this is to copy it manually within the function, but this seems like a waste of system resources (note that in the actual code I'm using "$var" is a huge array).
PHP Code:
function myfunc() {
global $var;
$varcopy = $var;
$varcopy++;
}
What I'd really like is a keyword instead of global like from_global_as_copy.
Any ideas?
This isn't crucial (my function is working fine), but I would like, at some point, to optimize the code.
EDIT: I seem to have found my answer. Instead of using global $var; I should use:
$var = $GLOBALS['var'];
Does anyone have any other thoughts on this?
Bookmarks