Page 1 of 1

including files

Posted: Mon Nov 21, 2005 9:27 pm
by alex.barylski
Is there any way I can inlcude a PHP file with a few $GLOBALS inside a function...but...

I need those globals to be ONLY visible inside the scope of the function

When the function ends...the globals are removed.... :(

I know $GLOBALS are considered super globals...they reach scope of every module...

But is there a way to circumvent this issue using eval and fopen or something???

Or does this technique still cause the globals to become super globals???

p.s-THEY NEED TO BE $GLOBALS nothing else!!!

Cheers :)

Posted: Mon Nov 21, 2005 9:30 pm
by hawleyjr

Code: Select all

$var1 = 'abcdef';

function callMe(){
global $var1;

$myTempVar = $var1;

$myTempVar = 'ghijklmn';

return $myTempVar;

}

Posted: Tue Nov 22, 2005 12:44 am
by josh
Hm, it sounds like you're describing what a class does, the variable is only accessible by the functions within that class

So for instance

Code: Select all

class foo {

     var $foo;

     function bar {
          return($this->foo);
     }

}