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

WordPress Trac noreply at wordpress.org
Mon Oct 22 05:15:31 UTC 2012


#22251: Helper function to simplify checking for constants
-------------------------+------------------------------
 Reporter:  evansolomon  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------------------

Comment (by MikeSchinkel):

 Replying to [comment:13 rmccue]:
 > I really like this, but how do we ensure `$wp` is defined before `wp-
 config.php`? If we don't, there'll be warnings (at least) from PHP. I
 guess adding `$wp = (object) array();` to the top of `wp-config.php` by
 default is probably the easiest way.

 This is the rest of the P.O.C. code.  I have it placed in `/wp-load.php`
 just before `wp-config.php` is called:

 {{{
 class wp_const {
   var $LEGACY_CONSTANTS = true;
   function __set( $property_name, $value ) {
     if ( $this->LEGACY_CONSTANTS && ! defined( $property_name ) ) {
       define( $property_name, $value );
     }
     $this->$property_name = $value;
   }
   function __get( $property_name ) {
     if ( preg_match( '#^[A-Z_0-9]+$#', $property_name ) ) {
       $this->$property_name = false;
     }
     return $this->$property_name;
   }
 }
 $wp = new wp_const();
 }}}

 Actually, I also have added all that same code to the `WP` class also.
 Too bad [http://php.net/manual/en/language.oop5.traits.php Traits] are not
 supported in PHP 5.2...

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22251#comment:14>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list