Re: [performance] === much faster than & and == and other interesting performance stats
| From: | Daniel Beckham | Date: | Wed, 07 Jun 2000 18:15:19 +0000 |
| Subject: | Re: [performance] === much faster than & and == and other interesting performance stats | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-20489@lists.php.net to get a copy of this message | ||
I use if($var) myself, but I come from a heavy Perl background and it's quite normal to assume truth values in the Perl world. A co-worker who has only programmed C and PHP will use the if($var==true) method often and I belive it's just what style he's accustomed to. One caveat with doing that though... if you are testing a string value such as a username returned from a form, it's better to test if(strlen($var)) because the $var could easily contain the character 0, which is evaluated as false, even though there is data in the variable. It's the same with the empty() statement. A string containing the character 0 will evaluate to false.
Daniel
At 07:31 PM 06/07/2000 +0200, you wrote:
2.) Another test a)"if ($var)" against b)"if($var==TRUE)" against c)"if (isset($var))" I remembered that some people don´t write "if ($var)" if they want to check if a variable is set (and != 0), they write "if($var==TRUE)", I don´t know if that´s popular, but I can´t advise anyone to use the longer version. (b) is about 9 times slower than (a), I did not expect this to be so much... I could not measure if (a) or (c) is faster, the results were close to each other, although they have a bit different meaning.