|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10678 distinction between false and "0" (string)
Submitted: 2001-05-04 19:21 UTC Modified: 2001-05-04 20:11 UTC
From: ms at marcant dot net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.4pl1 OS:
Private report: No CVE-ID: None
 [2001-05-04 19:21 UTC] ms at marcant dot 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:


if (strstr($haystack,"0")==false)
        { echo ' oh no.. '; }


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-04 19:34 UTC]
This has been discussed several times on the mailing lists;
check the archives at

The answer is in the manual:

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";

 [2001-05-04 20:11 UTC] ms at marcant dot net
ah .. sorry. thanks for the explanation.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Sep 28 19:05:53 2022 UTC