RE: Setting flags versus checking for existing/nonexisting values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2006-08-15 at 10:12 -0700, Chris W. Parker wrote:
> Brad Bonkoski <mailto:bbonkoski@xxxxxxxxxxxxxx>
>     on Tuesday, August 15, 2006 10:04 AM said:
> 
> > Pros: potentially more readable code.
> > Cons: Wasted energy typing unnecessary lines of code.
> > Really I would say it comes down to coder preference.
> > 
> > (and why would you avoid the latter all together?  Testing a boolean
> > may be cleaner, but setting the boolean still relies on the value of
> > $value, so if that value was fubar then the boolean would be too.)
> 
> Thanks for the response. Those are basically the same assumptions I had.
> I was curious to find out if there were more points I should be aware
> of.
> 
> To answer your question, in case the cons outweigh the pros. If I felt
> an overwhelming majority of the people on the list said, "In my
> experience you should always set flags because you'll run into a, b, c,
> d, e, f, g, etc." I would probably agree to avoid the latter practice
> altogether.

If it's just the mere existence that determines the value then isset()
is fine. But if the value is determined by a boolean value of the
variable and defaults to some value when not set, then I almost always
assign to a flag so that subsequent checks don't need to perform both
the isset() check and the value check (presuming you care about E_NOTICE
which I do :)

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux