Re: comparing a string

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

 



Rafael wrote:

A single "=" it's an assignment, not a comparison; and though it sometimes work, you shouldn't compare strings with "==", but using string functions, such as strcmp()... or similar_text(), etc.


This is PHP, not C. Operators such as == support strings for a reason, people should use them as such.

If you need to ensure type, (so that 0 == "foo" doesn't return true), then you can use ===.

Using a function call that does more than you need when there is an operator to achieve the same goal is bad advice. Not to mention the fact that it leads to harder to read code. Which of these has a more readily apparent meaning?

if ( strcmp($foo,$bar) == 0 )

if ( $foo === $bar )

Regards, Adam Zey.

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