You are here: Re: [PHP] Str to Int « PHP « IT news, forums, messages
Re: [PHP] Str to Int

Posted by Rick Emery on 01/22/06 00:56

Quoting tg-php@gryffyndevelopment.com:

> 3. if ($cardID = '' || is_int($cardID))
> As someone mentioned, $cardID = '' makes an assignment, doesn't
> test for true/false. Change to $cardID == ''. And this statement
> SHOULD come up "true" as a whole because $cardID = '' should always
> be true (unless the assignment fails). So regardless of
> is_int($cardID) succeeding or failing, $cardID = '' should be true
> so this statement will always be true.

A trick I read about during my time of learning best practices: if
comparing against a literal or constant, place the literal or constant
on the left side of the expression. For example,

if ('' == $cardID) {

instead of

if ($cardID == '') {

That way, if you accidentally use "=" instead of "==", you should get
an error because you can't assign something to a literal or constant.

Hope this helps somebody,
Rick
--
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return"
-- Leonardo Da Vinci

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация