RE: [PHP] include/require inside of function

From: Date: Tue, 08 Jul 2003 11:10:37 +0000
Subject: RE: [PHP] include/require inside of function
Groups: php.general 
Request: Send a blank email to php-general+get-154334@lists.php.net to get a copy of this message
> -----Original Message----- > From: Ow Mun Heng [mailto:ow.mun.heng@wdc.com] > Sent: 07 July 2003 04:34 > > Here's My question, a variable is not actually global is not > actually global until I make it global through "global > $make_this_global" > and then I can assess it using $GLOBAL[$make_this_global]. Not correct. Variables used in the global scope are global, and appear in the $GLOBALS array as soon as they come into existence. A global statement is used within a function merely to declare that you wish to use one of those variables in that function, where it would otherwise not be available. It's sort of equivalent to saying "when I use variable $x in this function, I actually want it to be $GLOBALS['x']" -- or, in PHP terms, $x = &$GLOBALS['x']. > > Another method would be to "global"ise it on demand by writing a > little function. (like Rasmus) > > I did it like this --> > > > ---create_globals.php------------ > function create_global($passed_variable) > if (isset ($GLOBALS[$passed_variable])) > { > return $GLOBALS[$passed_variable]; > } > ---------------end----------------- > > --------config.php------------------ > $page_title = "Page Title of Web Page" > ---------end------------------------ > > ----------index.html---------------- > require_once ('create_globals.php'); > > $local_variable = create_global( 'main_title') > echo "My Page Title is".$local_variable; > --------------end--------------------- > > > Hence This way I can make it global-on-demand. > > Maybe a better way to do it would be to > > ---------------config.php----------- > global $page_title = "Alternative Way" > ----------------end----------------- I'm really not sure what you're getting at here, but I think it may be based on a misunderstanding. If you could explain exactly what it is you're trying to do, someone might be able to offer some better help. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#154334) next »