php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
Description:
------------
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:
---------------
<?php
$foobar = array();

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

Expected result:
----------------
It should not output 'fail'

Actual result:
--------------
Outputs fail

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-24 23:15 UTC] sixd@php.net
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] sixd@php.net
-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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 03:01:32 2024 UTC