including files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

including files

Post 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 :)
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

$var1 = 'abcdef';

function callMe(){
global $var1;

$myTempVar = $var1;

$myTempVar = 'ghijklmn';

return $myTempVar;

}
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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);
     }

}
Post Reply