On Tue, Jan 25, 2022 at 5:11 PM Rowan Tommins <rowan.coll...@gmail.com> wrote:
> 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. > > Bruce and Rowan - thanks for the suggestions. I like both of those and I think they'll work in our situation. Appreciate you taking the time to recommend some solutions instead of just telling me I'm doing it the wrong way. > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > -- Chase Peeler chasepee...@gmail.com