[Solar-talk] proposed usage of constants in place of strings for status in Solar_Auth_Adapter

Leo Chiao leo.chiao at gmail.com
Sun Mar 23 17:07:51 CDT 2008


Thanks for your input Antti, I completely overlooked that aspect and now
notice that he is using locale strings to populate the "status_text" flash
based on the user status string.

Do you mind elaborating on your point about clumsy if/else structures? If a
variable is used soley to signify state or won't change, why would you avoid
defining a const for it?


On Sun, Mar 23, 2008 at 5:49 PM, Antti Holvikari <anttih at gmail.com> wrote:

> On Sun, Mar 23, 2008 at 11:41 PM, Leo Chiao <leo.chiao at gmail.com> wrote:
> > Paul,
> >
> > Is there any reason why you chose to use strings such as INVALID, IDLED,
> etc
> > as the status indicators in Solar_Auth_Adapter? I'm thinking that a
> class
> > level constant would be more suited for this purpose.  In the scenario
> where
> > someone might want to check the status, using constants would allow for
> > easier debugging if someone mistyped the status string code.  .
> >
> > Let's assume you add constants named STATUS_IDLED, STATUS_VALID, etc.
> and
> > $user is a Solar_User instance:
> >
> > if ($user->auth->status == 'IDLE') {
> >
> > }
> >
> > versus
> >
> > if ($user->auth->status == Solar_Auth_Adapter::STATUS_IDLE) {
> >
> > }
> >
> >
> > In the first case, the if statement would never get run due to the typo
> of
> > "IDLE" vs "IDLED" and no error would be shown. Using a constant, you
> would
> > see an error and be able to recognize the source of the typo much
> easily.
>
> Simple, strings work with localization strings. Personally, my opinion
> is that constants shouldn't be used *at all* with PHP. They lead to
> very clumsy if/else structures which I think something as dynamic as
> PHP code can't afford.
>
> Sorry, I'm not Paul :-(. Just had to give my $0.02.
>
> --
> Antti Holvikari <http://anttih.com>
> _______________________________________________
> Solar-talk mailing list
> Solar-talk at lists.solarphp.com
> http://mailman-mail3.webfaction.com/listinfo/solar-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman-mail3.webfaction.com/pipermail/solar-talk/attachments/20080323/90c03a86/attachment.html


More information about the Solar-talk mailing list