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

From: Date: Sun, 24 Sep 2006 17:32:46 +0000
Subject: Re: Re: question about defining constants and pear coding standards
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-44034@lists.php.net to get a copy of this message
On 9/24/06, Terra Frost <terrafrost@gmail.com> wrote:
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"?
No, I just don't know if you're planning on making SomeObject PHP4 compatible. If you are, use the PHP4 version.
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);
Yes, it's 1 more line of code, but it's the more supported way of doing things in PEAR. It also allows the user to change modes partway through a script.
...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.
No, of course it wouldn't, as your code would check to see if it's set and if it's not it would use a default. if (isset($options['mode']))
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.
As above, of course it can. -- Justin Patrin

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