[wp-trac] [WordPress Trac] #22251: Helper function to simplify checking for constants

WordPress Trac noreply at wordpress.org
Thu Oct 5 13:03:47 UTC 2017


#22251: Helper function to simplify checking for constants
----------------------------+-----------------------------
 Reporter:  evansolomon     |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  Future Release
Component:  Bootstrap/Load  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  dev-feedback    |     Focuses:
----------------------------+-----------------------------

Comment (by schlessera):

 Just as a quick note:

 A generalized function like the above should not return `false` if the
 constant is not defined (a problem that @nacin had already pointed out),
 but rather let the consumer provide the fallback value to use in that
 case:

 {{{#!php
 function wp_constant( $constant, $fallback = false ) {
     return defined( $constant ) ? constant( $constant ) : $fallback;
 }
 }}}

 But apart from that detail, I also think that this is just a crutch that
 further obfuscates the underlying problem: WordPress Core needs a
 standardized system for its bootstrap configuration.

 Most systems nowadays use a configuration container of some sorts, and
 allow for the bootstrapping configuration defaults to be overridden by
 environment variables, so that you have control over them at the server
 level without the need to modify files. Most implementations then let you
 use real environment variables and `.env` files interchangeably.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/22251#comment:31>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list