Re: Export local variable to global variable scope?



On Sat, 29 Sep 2007 19:27:28 +0200, howa <howachen@xxxxxxxxx> wrote:
On 9 29 , 9 49 , Bruno Barros <rage...@xxxxxxxxx> wrote:
On 29 Sep, 13:23, howa <howac...@xxxxxxxxx> wrote:
> I have a function, e.g.

> function foo() {
> include("bar.php");

> }

> and the bar.php contain contents e.g.

> $global_v1 = "abc";
> $global_v2 = "def";

> I want to execute function foo(), but at the same time, let the
> variables declared in bar.php to have global scopem is it possible?
function foo() {
global $global_v1;
global $global_v2;

include "bar.php";

}
Assume that I know nothing about the stuffs inside bar.php...is it
possible?

function foo(){
include_once('bar.php');
foreach(get_defined_vars() as $name => $value){
if(!in_array($name, array('_GET','_POST','GLOBALS','_COOKIE','_SESSION','_ENV','_FILES','_REQUEST','_SERVER')))
$GLOBALS[$name] = $value;
}
}

It's really kinda ugly though.
--
Rik Wasmus
.



Relevant Pages