Re: Str to Int

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

 



Quoting tg-php@xxxxxxxxxxxxxxxxxxxxxx:

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

--
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