defining constants in a config file? |
(12-14-2015, 11:13 PM)ivantcholakov Wrote: http://stackoverflow.com/questions/38033...s-constant Very interesting: PHP Code: // Works as of PHP 7 Martin7483 Wrote:You have a multi language website, I think you would then want to change the language setting in your config file to match your visitors chosen language.This seems like a pretty interesting example, and language is certainly a consideration on my site, but one would probably not want to change what's in our config file -- certainly not on a user-by-user basis. In our case, language is determined by the requesting url and the language for a given request would be fixed for the entire duration of a page request. Martin7483 Wrote:making this kind of assumption could get you in to trouble down the roadI was wondering if it might and have not yet been able to identify any real risk except for the possibility of constant name collisions with 3rd party libraries. I think the likelihood of this is small. Also wondering if using namespaces might help. Martin7483 Wrote:If you are worried about misspelling and bugs, maybe you could do a combination. Use constants for the names of your config items instead of the values.I had considered this but ruled it out. It just seems ridiculous and doesn't solve the problem of name collisions because constants are global AFAIK. I had considered one other approach: attaching all my constants to some class: PHP Code: // this class would be loaded by an autoloader I have set up if I put it in the right place InsiteFX Wrote:I define all my constants at the bottom of ./application/config/constants.phpSeems to me that will make it more difficult for you to upgrade CodeIgniter when you need to because that file is one of the core CI files. If CI chooses to add new constants to this file, you'll be forced to do a merge to make sure your added constants and CI's added constants are all in the file. |
Messages In This Thread |
defining constants in a config file? - by sneakyimp - 12-14-2015, 03:48 PM
RE: defining constants in a config file? - by ivantcholakov - 12-14-2015, 06:07 PM
RE: defining constants in a config file? - by sneakyimp - 12-14-2015, 06:44 PM
RE: defining constants in a config file? - by ivantcholakov - 12-14-2015, 11:13 PM
RE: defining constants in a config file? - by sneakyimp - 12-15-2015, 10:22 AM
RE: defining constants in a config file? - by Martin7483 - 12-15-2015, 02:00 AM
RE: defining constants in a config file? - by InsiteFX - 12-15-2015, 04:25 AM
RE: defining constants in a config file? - by InsiteFX - 12-15-2015, 12:33 PM
RE: defining constants in a config file? - by Martin7483 - 12-16-2015, 03:09 AM
|