php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35041 if (strpos("123","1")===true) doesn't work. if (strpos("123","1")!==false) does
Submitted: 2005-11-01 00:12 UTC Modified: 2005-11-02 03:13 UTC
From: john dot clements at publicinfo dot net Assigned:
Status: Closed Package: Strings related
PHP Version: 5CVS-2005-10-31 (snap) OS: Windows xp pro sp2
Private report: No CVE-ID: None
 [2005-11-01 00:12 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-01 07:36 UTC] 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-02 03:13 UTC] john dot clements at publicinfo dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 10:01:28 2024 UTC