On 25/01/2022 19:44, Chase Peeler wrote:
If we start throwing exceptions, which can't be suppressed, it will make
this much more difficult to read since the constants.php will have to be
updated:
if(!defined('dbserver')){
define('dbserver','productiondb.example.com');
}
if(!defined('otherconstant')){
define('otherconstants','foobar');
}
A wrapper function for this use case is entirely trivial:
function define_if_not_defined($name, $value) {
if ( ! defined($name) ) {
define($name, $value);
}
}
Give it a short name like 'def', and your config file actually becomes
shorter:
def('dbserver', 'productiondb.example.com');
def('otherconstants', 'foobar');
"define" itself is just a function name, not a reserved word, so you
could even declare the above as "define" in a namespace, then add "use
function SomeNamespace\define;" and leave the rest of the file alone.
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php