[wp-hackers] WPMU VHOST constant

Aaron D. Campbell aaron at xavisys.com
Wed Aug 5 19:40:48 UTC 2009

If you use constant(), you don't need really need to use defined() since 
it returns null if the constant if undefined.  Instead you can just 
suppress the warning, so either of these should work:
if ( @constant('VHOST') == 'yes' ) {}
if ( defined('VHOST') && VHOST == 'yes' ) {}

The only edge case where those would perform differently is if you were 
trying to tell if the constant was not defined vs being defined as null:
//MYCONST purposely not defined
if ( @constant('MYCONST') == null ) {
  //This runs
if ( defined('MYCONST') && MYCONST== null ) {
  //This does not run

Will Anderson wrote:
> On the other hand, I really would argue that it's worth the extra bit of
> code to check that VHOST is defined. A plugin that needs to worry about
> sub-domains versus sub-directories probably won't run well on a
> WordPress.org install, but all the same, it could help avoid a warning if
> VHOST isn't defined (as would be the case in a WP.org site). It's also a
> core PHP lookup, so it will create a negligible performance hit to run the
> check.

More information about the wp-hackers mailing list