Re: A Review Request
| From: | Joshua Kehn | Date: | Thu, 19 May 2011 19:26:00 +0000 |
| Subject: | Re: A Review Request | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-312926@lists.php.net to get a copy of this message | ||
On May 19, 2011, at 3:16 PM, Alex Nikitin wrote:
> PHP_SELF requires no processing (i.e. there is no need to do basename())
>
> strcmp is binary-safe, i prefer and recommend using string-safe comparison
> functions for strings... here is an example of why:
>
> $value = 0;
> if($value=="not zero") {
> echo "oopsie, how did this happen, lets see how this works with strcmp
> (or === which i would advise)";
> if(strcmp($value, "not zero") == 0) {
> echo "You wont see this";
> } else {
> echo "Because strcmp works correctly";
> }
> }
>
> you can also use the exact comparator ===, as it compares types, it would
> work well as well. Infact if you dont need to determing anything about the
> string, i would suggest using the === operator as it is significantly
> faster:
>
> timed: 0m0.724s
> <?php
> for($i=0; $i<=10000000; $i++){
> if(1 === "submit") {
> continue;
> }
> }
>
> timed: 0m4.785s
> <?php
> for($i=0; $i<=10000000; $i++){
> if(strcmp(1, "submit")==0) {
> continue;
> }
> }
>
> --
> The trouble with programmers is that you can never tell what a programmer is
> doing until it’s too late. ~Seymour Cray
I almost exclusively use ===.
Regards,
-Josh
____________________________________
Joshua Kehn | Josh.kehn@gmail.com
http://joshuakehn.com