Welcome Guest, Not a member yet? Register   Sign In
defining constants in a config file?
#1

(This post was last modified: 12-14-2015, 03:49 PM by sneakyimp.)

I'd like to define some constants in a config file. For example, here's a config file:
PHP Code:
// application/config/my-constants.php
define("ABCD_MY_CONSTANT""my constant value"); 
And then in my controller:
PHP Code:
$this->config->load('my-constants');
echo 
"the value is " ABCD_MY_CONSTANT

I fully realize that the constants will exist in in the global scope of my application, but the prefix I use ("ABCD" in this case) should pretty much guarantee no name conflicts. I realize this is a bit old school, but I like it because the constants defined this way will be interpreted by our developers' IDEs such that we don't have to worry as much about devs incorrectly typing scalar strings when trying to refer to values defined in some config file. The typing of scalar constants (e.g., $this->config->item("some-scalar-string") ) is one of the biggest sources of bugs in my experience. Defining the constants such that the IDE makes them available via autocomplete seems to largely remedy this problem.

I welcome any input on this matter.
Reply


Messages In This Thread
defining constants in a config file? - by sneakyimp - 12-14-2015, 03:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB