#35041 [Bgs->Csd]: if (strpos("123","1")===true) doesn't work. if (strpos("123","1")!==false) does
| From: | john dot clements at publicinfo dot net | Date: | Wed, 02 Nov 2005 02:13:01 +0000 |
| Subject: | #35041 [Bgs->Csd]: if (strpos("123","1")===true) doesn't work. if (strpos("123","1")!==false) does | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-87383@lists.php.net to get a copy of this message | ||
ID: 35041
User updated by: john dot clements at publicinfo dot net
Reported By: john dot clements at publicinfo dot net
-Status: Bogus
+Status: Closed
Bug Type: Strings related
Operating System: Windows xp pro sp2
PHP Version: 5CVS-2005-10-31 (snap)
New Comment:
I reported this as a documentation issue using the web form found from
the manual. The response was to report it as a bug. So I did. Now I
will go back and report it again as a documentation issue and submit my
own documentation comment.
Previous Comments:
------------------------------------------------------------------------
[2005-11-01 07:36:31] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
strpos doesn\'t return true on success but the position
------------------------------------------------------------------------
[2005-11-01 00:12:28] john dot clements at publicinfo dot net
Description:
------------
This is a problem with === true and !== true whether used with strpos
or with array_search and presumably with other functions.
This also fails under PHP 4.3.10 on FreeBSD 4.8-STABLE,
but that is a hosted server and I can't upgrade it to test.
I have done further testing and found that
checking for === false or !== false is OK:
=== false works when statement is true
=== false works when statement is false
=== true doesn't work when statement is true
=== true works when statement is false
!== true doesn't work when statement is true
!== true works when statement is false
!== false works when statement is true
!== false works when statement is false
Pls get in touch if you would like the code to show that.
Reproduce code:
---------------
<?php
if (strpos("hey","h") === true) print "1. worked \n";
else print "1. didn't work\n";
if (strpos("hey","h") !== false) print "2. worked \n";
else print "2. didn't work\n";
?>
Expected result:
----------------
1. worked
2. worked
Actual result:
--------------
1. didn't work
2. worked
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35041&edit=1