|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63348 Unexpected behaviour with strpos()
Submitted: 2012-10-24 19:09 UTC Modified: 2012-10-24 23:26 UTC
From: aleksey dot v dot korzun at gmail dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 5.3.18 OS: *Nix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: aleksey dot v dot korzun at gmail dot com
New email:
PHP Version: OS:


 [2012-10-24 19:09 UTC] aleksey dot v dot korzun at gmail dot com
Please review code snippet below, expected behaviour is that code within if 
statement will not be executed (since the value was not found).

Test script:
$foobar = array();

if(strpos($foobar, 'something') !== false) {
	echo 'fail';

Expected result:
It should not output 'fail'

Actual result:
Outputs fail


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-24 23:15 UTC]
The code actually gives this message first:
PHP Warning:  strpos() expects parameter 1 to be string, array given

It's standard for PHP to behave like this for parameter parsing errors. E.g. all 
but a few of the str* functions are implemented using 'return' in this case. Only 
strrpos, strripos, strpbrk, (and substr_compare) use RETURN_FALSE.
 [2012-10-24 23:15 UTC]
-Status: Open +Status: Not a bug
 [2012-10-24 23:26 UTC] aleksey dot v dot korzun at gmail dot com
I'm aware of the notice, but in my opinion that this should be handled within the 
function and return false .vs null as in no match was found.

- $0.2
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Mar 23 05:03:38 2023 UTC