Re: Re: question about defining constants and pear coding standards
| From: | Pierre | Date: | Sun, 24 Sep 2006 08:19:33 +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-44023@lists.php.net to get a copy of this message | ||
On Sat, 23 Sep 2006 17:03:58 -0700
papercrane@gmail.com ("Justin Patrin") wrote:
> On 9/23/06, Pierre <pierre.php@gmail.com> wrote:
> > On Sat, 23 Sep 2006 10:18:33 -0500
> > terrafrost@gmail.com (Terra Frost) wrote:
> >
> >
> > > <?
> > > define('SOME_OBJECT_MODE',SOME_OBJECT_PHP);
> > >
> > > $a = new Some_Object();
> > >
> > > echo $a->toString();
> > > ?>
> > >
> > > If SOME_OBJECT_MODE wasn't specified, a default mode could be
> > > used, by (in Some_Object.php) doing something like...
> > >
> > > if ( !defined('SOME_OBJECT_MODE') ) {
> > > define('SOME_OBJECT_MODE',SOME_OBJECT_PHP);
> > > }
> > >
> > > Anyway, the only thing I'm wondering is... would this be okay,
> > > per the Pear coding standards?
> >
> > It is. I would name the constant SOME_OBJECT_DEFAULT_MODE though.
> >
>
> I disagree. For PHP4 code you should use PEAR::getStaticProperty().
> $options =& PEAR::getStaticProperty('SomeObject', 'options');
> $options = array('mode' => SOME_OBJECT_PHP);
Using a constant for this kind of problem is a perfectly valid solution.
> 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;
Yes, this is the cleanest way for php5+ only packages.
-- Pierre