PHP 4.0 Bug #10678 Updated: distinction between false and "0" (string)
| From: | ms at marcant dot net | Date: | Sat, 05 May 2001 00:11:17 +0000 |
| Subject: | PHP 4.0 Bug #10678 Updated: distinction between false and "0" (string) | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-53978@lists.php.net to get a copy of this message | ||
ID: 10678
User Update by: ms@marcant.net
Status: Bogus
Bug Type: *General Issues
Description: distinction between false and "0" (string)
ah .. sorry. thanks for the explanation.
Previous Comments:
---------------------------------------------------------------------------
[2001-05-04 19:34:48] torben@php.net
This has been discussed several times on the mailing lists;
check the archives at http://marc.theaimsgroup.com.
The answer is in the manual:
http://www.php.net/manual/en/language.operators.comparison.php
Basically, 0 is a false value but is of type int. You want
to test for a return value of false (type boolean), so you
need the 'identical' comparison operator: '==='.
$haystack = '1230';
if (strstr($haystack, '0') === false) {
echo "oh non";
}
---------------------------------------------------------------------------
[2001-05-04 19:21:26] ms@marcant.net
There is a subtle problem with functions returning 'false' as
an return status indication.
Take for example strstr(haystack, needle).
The function returns 'false' to indicate that <needle> could not
be found in <haystack> or returns the substring of haystack
starting with <needle>
With certain strings the above assertion is not true with php:
$haystack='1230';
if (strstr($haystack,"0")==false)
{ echo ' oh no.. '; }
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=10678