By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,638 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,638 IT Pros & Developers. It's quick & easy.

using global var (global settings?)

P: n/a
Hi all!

I have an app which reads from certain servers, but I'd like to have
them in am ini-file.

I made this up, but I need those vars to be visible in functions
too.... how do I do that?

BR
Sonnich

// default ini values
$dir1="\\\\server1\\finance";
$dir2="\\\\server2\\design\\";
// read in settings
$ini=fopen("config.ini", "r");
while(!feof($ini))
{
$line=fgets($ini, 100);
if(stristr($line, 'dir1') == TRUE)
{
$dir1=strstr($line, '=');
$dir1=trim(substr($dir1, 1, 1000));
}
else if(stristr($line, 'dir2') == TRUE)
{
$dir2=strstr($line, '=');
$dir2=trim(substr($dir2, 1, 1000));
}
}
fclose($ini);

Jun 19 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 19 Jun 2006 09:56:17 -0700, "Sonnich" <so************@elektrobit.com> wrote:
I have an app which reads from certain servers, but I'd like to have
them in am ini-file.

I made this up, but I need those vars to be visible in functions
too.... how do I do that?


Various options, some of which are:

(1) Access the configuration values through functions instead of globals.
(2) Define them as constants; they're always in scope.
(3) Use the "global" statement in the function.
(4) Reference the variables through $GLOBALS.
(5) It sounds like you want to register your own superglobals - this is not
trivial; runkit can do it, but that's fairly magic and unlikely to be installed
on most servers. http://www.php.net/manual/en/runkit.sandbox.php
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jun 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.