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

From: Date: Mon, 25 Sep 2006 17:19:58 +0000
Subject: Re: Re: question about defining constants and pear coding standards
References: 1 2 3 4 5 6 7  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-44056@lists.php.net to get a copy of this message
Justin Patrin wrote:
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. That will *not* solve anything. getStaticProperty will try to reference $properties['Some_Object']['mode'] which is *only* going to exist if those two lines were added. But what if those lines haven't been added? Adding a default: in the switch statement isn't going to change the fact that getStaticProperty is trying to reference something that was never initialized.
I've snipped the rest, I don't have time to read a huge thread just to tell you how basic logic works.
Maybe you should take the time to read it, because you apparently need a reminder about such "basic logic"...

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