Forum Moderators: coopster

Message Too Old, No Replies

Accessing Variables from within Functions

I need to access external variables from within function

         

erikcw

4:33 am on May 19, 2004 (gmt 0)

10+ Year Member



Hi All,

A while back I found a php function that would make all variables in a script available to a custom function.

ie:

$test1 = 1

function test() {
//STATEMENT GOES HERE

echo $test

}

I haven't been able to find this function again. Any ideas?

jatar_k

4:50 am on May 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



PHP Variable Scope [ca2.php.net]

that is the right answer but I doubt that is what you are looking for, maybe this

Using Register Globals [ca.php.net]

erikcw

5:18 am on May 19, 2004 (gmt 0)

10+ Year Member



thanks for your reply jatar_k.

While the variable scope method may be a way to go, it is not the one I am looking for.

The function I discovered was in a php.net user comment on function and making variables globabaly available - I just can't seem to find that post again or rmember the script that I used it in for testing.

If I remeber correctly, the function (if it was a function) started with an "e" (maybe explode, expand...?)

I'm lost!

coopster

12:44 pm on May 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



extract [php.net]?

erikcw

6:15 pm on May 19, 2004 (gmt 0)

10+ Year Member



Thanks Coopster!

I finally found the script that I had used it in, and the code was:

extract($GLOBALS);


function test() {
extract($GLOBALS);

statements & variables

}

Thanks for your help!