Re: smarter way to write config file?

From: Date: Tue, 16 Apr 2002 08:53:44 +0000
Subject: Re: smarter way to write config file?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-93132@lists.php.net to get a copy of this message
Justin French <justin@indent.com.au> has the same first name as me :) and wrote: > Currently i've got a config file for each website, and I split it into > essentially two config files, based on the server name, so that I can have 1 > file for both my local server and the live server. > > something like: > > <? > > if($local) > { > $cfgAdminEmail = "justin@indent.com.au"; > $cfgReportErrors = 1; > $cfgSendMail = 0; > } > else > { > $cfgAdminEmail = "webmaster@foo.com"; > $cfgReportErrors = 0; > $cfgSendMail = 1; > } > > ?> > > But of course, there's more like 20 config elements. The small problem I'm > having is making sure that I keep both halves (live and local) the same (but > with different settings). > > > What i was hoping was that there may be a way of writing the config once, > and having it work in both situations, perhaps with a switch, or with some > other language construct I have no idea about: > > I know this isn't the answer, but I was hoping for something like: > > <? > $cfgAdminEmail = "justin@indent.com.au|webmaster@foo.com"; > $cfgReportErrors = "1|0; > $cfgSendMail = "0|1"; > ?> > > Where both the options "local|live" were declared in one hit. > > > Whatever solution there is (arrays? switches?) it has to be easy to > maintain, otherwise it's a step backwards I guess. > > > Any suggestions appreciated, or pointers to stuff in the manual i've never > heard of!!! You could do it by making each variable an array with a key of 'local' and 'live' like this: <? $cfgAdminEmail = array("local" => "localaddress", "live" => "liveaddress"); etc. etc. ?> Then you could set something like $server to "local" or "live" and refer to the var's by $cfgAdminEmail[$server]; Justin

« previous php.general (#93132) next »