Re: [PHP4BETA] propose for bool -> string conversion:
| From: | Rasmus Lerdorf | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: [PHP4BETA] propose for bool -> string conversion: | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-1810@lists.php.net to get a copy of this message | ||
> Then tell me the magic checks. Running
>
> function c($x) { if($x) echo "found\n"; else echo "not found\n"; }
>
> $string = "abc";
> c(strpos($string,"a"));
> c(strpos($string,"z"));
>
> prints:
>
> not found
> not found
Because you can't just do if($x) since both "" and 0 are treated as false.
That doesn't mean the function isn't working. The function is defined to
return a number from 0-n on a match and "" (false) on a failure. It's not
the most consistent thing in the world, but having it return 1, for
example, would also suck because then you would have to fudge the return
value when you wanted to use it directly as a string index. ie.
$string[strpos($a,"a")];
-Rasmus