Bug #10678 Updated: distinction between false and "0" (string)
| From: | torben@php.net | Date: | Fri, 04 May 2001 23:34:49 +0000 |
| Subject: | Bug #10678 Updated: distinction between false and "0" (string) | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-53973@lists.php.net to get a copy of this message | ||
ID: 10678
Updated by: torben
Reported By: ms@marcant.net
Old-Status: Open
Status: Bogus
Bug Type: *General Issues
PHP Version: 4.0.4pl1
Assigned To:
Comments:
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 no\n";
}
Previous Comments:
---------------------------------------------------------------------------
[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.. '; }
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10678&edit=2