[wp-trac] [WordPress Trac] #22251: Helper function to simplify checking for constants
WordPress Trac
noreply at wordpress.org
Mon Oct 22 05:08:14 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 rmccue):
Replying to [comment:10 MikeSchinkel]:
> What is really wrong with allowing them to be set anywhere, in practice?
After many years experience I'm still looking for a good reason that
"constants" need to remain immutable.
I completely agree, but I think if they're going to be uppercase, then
they need to be only settable once so that they act like constants. That's
why my personal preference would be to use lowercased properties just as
normal properties.
> Could you elaborate on the potential problems?
That was for if they could only be set in `wp-config.php`, where I can see
problems with using includes in the config causing the complicated setter
stuff to fail. I think that's a complicated path, but I personally would
prefer eliminating the constants and constant-like behaviour
(immutability) in favour of simply using properties (also renaming some
such as `$wp->db['host'] = 'localhost'` etc.). This could be done
completely in a backwards compatible manner, since we're inventing these
from scratch, so as long as they check for the constants as well, it
should be fine, e.g.
{{{
class WP {
public $db = array( 'host' => '', /* ... */ );
// ...
public function set_from_constants() {
defined('DB_HOST') && $this->db['host'] = DB_HOST;
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22251#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list