php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #4202 if interprets "0" as "false" even when checking for "numeric value" vs "false"
Submitted: 2000-04-20 13:53 UTC Modified: 2000-04-20 15:25 UTC
From: shh at enovia dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0 Release Candidate 1 OS: Red Hat Linux 6.2
Private report: No CVE-ID: None
 [2000-04-20 13:53 UTC] shh at enovia dot com
Here is a script that reproduces the problem:

$string_1="<test>";
$string_2="test";
print("strrpos returns: \"".strrpos($string_1,"<")."\"<br>");
if(strrpos($string_1,"<")=="0") print "string_1 if is true<br>"; else print "string_1 if is false<br>";
print("strrpos returns: \"".strrpos($string_2,"<")."\"<br>");
if(strrpos($string_2,"<")=="0") print "string_2 if is true<br>"; else print "string_2 if is false<br>";

When run on PHP-4, Apache 1.3.12, Red Hat Linux 6.2 the output is:

strrpos returns: "0"
string_1 if is true
strrpos returns: ""
string_2 if is true     <---- This should be false!

When run on PHP-3, Apache 1.3.11, Red Hat Linux 6.1 the output is:

strrpos returns: "0"
string_1 if is true
strrpos returns: ""
string_2 if is false

PHP was configured using ./configure --with-pgsql=/usr/local/pgsql --with-apache=../apache_1.3.12 --enable-track-vars

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-04-20 14:09 UTC] joey at cvs dot php dot net
In PHP4, use === to test 
0 == FALSE
True (they have the same "value")
0 === FALSE
False (they are not the same datatype) 
 [2000-04-20 14:21 UTC] shh at enovia dot com
This script works properly on PHP4:

$string_1="<test>";
$string_2="test";
print("strrpos returns: \"".strrpos($string_1,"<")."\"<br>");
if(strrpos($string_1,"<")===0) print "string_1 if is true<br>"; else print "string_1 if is false<br>";
print("strrpos returns: \"".strrpos($string_2,"<")."\"<br>");
if(strrpos($string_2,"<")===0) print "string_2 if is true<br>"; else print "string_2 if is false<br>";

 [2000-04-20 14:59 UTC] joey at cvs dot php dot net
Great. Close it.
 [2000-04-20 15:05 UTC] shh at enovia dot com
How about updating the Migrating to PHP4 notes on the web to include this info... OK?
 [2000-04-20 15:25 UTC] joey at cvs dot php dot net
I will, as soon as I can get a straight answer from the Core
guys whether this is intentional or a bug...there is some
discussion on whether the string 0 should be false or not.

Thanks for the report!
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 14 19:00:01 2026 UTC