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

From: Date: Mon, 25 Sep 2006 17:04:44 +0000
Subject: Re: Re: question about defining constants and pear coding standards
References: 1 2 3 4 5 6  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-44055@lists.php.net to get a copy of this message
On 9/24/06, Terra Frost <terrafrost@gmail.com> wrote:
Justin Patrin wrote:
...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'])) So, basically, you're recommending I do this?: (test.php): <?php define('SOME_OBJECT_MODE_INTERNAL',1); define('SOME_OBJECT_MODE_EXTERNAL',2); include('PEAR.php'); class Some_Object {
    function Some_Object()
    {
        $mode = PEAR::getStaticProperty('Some_Object', 'mode');
        switch ($mode) {
            case SOME_OBJECT_MODE_INTERNAL:
                echo 'internal';
                break;
Try adding a default: here. As I said before, *your code needs to handle this*. It's not hard.
            case SOME_OBJECT_MODE_EXTERNAL:
                echo 'external';
        }
    }
}
I've snipped the rest, I don't have time to read a huge thread just to tell you how basic logic works. -- Justin Patrin

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