Re: Correct Coding
| From: | Jim Lucas | Date: | Thu, 07 Aug 2003 18:00:05 +0000 |
| Subject: | Re: Correct Coding | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158697@lists.php.net to get a copy of this message | ||
Could you explain a little better why this would make things better?
I don't understand how this would improve things.
Jim Lucas
----- Original Message -----
From: "Curt Zirzow" <curt@zirzow.dyndns.org>
To: <php-general@lists.php.net>
Sent: Thursday, August 07, 2003 10:28 AM
Subject: Re: [PHP] Correct Coding
> * Thus wrote Christopher J. Crane (ccrane@ikon.com):
> > Is this the best way to do this?
> >
> > if(isset($Task) && $Task == "Add") { Do something }
> >
> > I want to check if the variable is set and if so, if it is "Add".
>
> Yes, that is good. Remember, though, it is case sensitive so "ADD"
> wont match.
>
> Concerning the $Task == "Add", I'd like to make a comment. It can
> be a wise decision to compare your variables with strings like:
>
> if ("Add" == $Task)
>
> This can help preventing typo's like:
>
> if ($Task = "Add")
>
> I've seen people tear their hair out wondering why the if statement
> is always true even if $Task is not "Add". I don't see this method
> used very often but it can prevent serious logic typos.
>
>
> HTH,
>
> Curt
> --
> "I used to think I was indecisive, but now I'm not so sure."
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>