On Fri, 4 Jul 2003, Aric Caley wrote: > Is there anyway to include a file inside of a function and have the included > stuff be global? For instance if I defined a class or a function in that > include file, I want to be able to use that class outside of the function. > > On the documentation for include() a poster commented that it did indeed > work like this, but my testing indicates it does not. Everything stays > local to the function and goes away when the function ends. > > Is there a way?
Functions defined in included files are always global. So I guess it is just the variable you want to put out into the global symbol table. It's a little bit tricky, but you can do it like this: function foo($filename) { extract($GLOBALS, EXTR_REFS); include $filename; $arr = array_diff(get_defined_vars(),$GLOBALS); foreach($arr as $var=>$val) $GLOBALS[$var] = $val; } -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php