Re: Re: question about defining constants and pear coding standards

From: Date: Sun, 24 Sep 2006 14:43:10 +0000
Subject: Re: Re: question about defining constants and pear coding standards
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-44030@lists.php.net to get a copy of this message
Justin Patrin wrote:
<snip> I disagree. For PHP4 code you should use PEAR::getStaticProperty(). $options =& PEAR::getStaticProperty('SomeObject', 'options'); $options = array('mode' => SOME_OBJECT_PHP); and for PHP5 code you should use a class static property (which can be overridden by an instance property or something passed into the constructor). SomeObject::$mode = SomeObject::MODE_OBJECT_PHP;
If you're suggesting I have two versions of Some_Object, how is PEAR going to know which one to install when I type "pear install Some_Object"? Also, requiring users do something like... $mode =& PEAR::getStaticProperty('Some_Object','mode'); $mode = SOME_OBJECT_MODE_PHP; ...poses a problem for two reasons. First, it's more complicated than doing... define('SOME_OBJECT_MODE',SOME_OBJECT_MODE_PHP); ...and second... what happens if the $mode isn't explicitly specified? I'd like Some_Object to use a default mode at that point, however, I'm not so sure this would be possible using this method. With getStaticProperty, an undefined index will be referenced, in this scenario. If the error reporting is set to E_ALL, this would result in an error. I could surpress the error with a @, but this doesn't seem to be a particurarly elegant solution, regardless. The way I'd get around this, with defines, is by seeing if defined('...') was true or not. I don't think anything similar can be done with getStaticProperty.

« previous php.pear.dev (#44030) next »