RE: [PHP] Re: Inspiration for a Tombstone.
| From: | Robert Cummings | Date: | Fri, 27 Jun 2008 18:17:00 +0000 |
| Subject: | RE: [PHP] Re: Inspiration for a Tombstone. | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276083@lists.php.net to get a copy of this message | ||
On Fri, 2008-06-27 at 09:52 -0500, Boyd, Todd M. wrote:
> > -----Original Message-----
> > From: Jay Blanchard [mailto:jblanchard@pocket.com]
> > Sent: Friday, June 27, 2008 8:50 AM
> > To: tedd; php-general@lists.php.net
> > Subject: RE: [PHP] Re: Inspiration for a Tombstone.
> >
> > [snip]
> > And being dyslexic, I knew the 'Dan S' should have come first, but
> > didn't immediately recognize it as I was rushing to point out a
> > double equal-sign boo-boo made by Col.
> > [/snip]
> >
> > Had Col used the method we're speaking of here the error would have
> > been
> > thrown and he would have found the culprit post haste.
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> I think you guys are missing something: he wrote it with single equals
> signs on purpose. He was demonstrating how the one with the constant to
> the right of the assignment operator is a valid statement... and that
> putting the constant first will aid you in finding such mistakes.
>
> if("constant" = $variable){} // bombs, and lets you know right away you
> missed an =
> if($variable = "constant"){} // assigns rather than compares, but
> nonetheless is valid code
>
> To quote Colin: "As I very humorously hinted at in a earlier mail on
> this thread, it is a very, very good idea to get into the habit of
> putting constants *first* in if/while/etc statements." So, I'm sure he
> is well familiar with this "method we're speaking of." :)
I will never do it... it looks ugly, especially when performing multiple
if comparisons on the variable. Additionally, using a little red to
highlight the assignment operator but not the comparison operator works
just as well. Make machines work for you, not the other way around.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP