Bug #63348 [Nab]: Unexpected behaviour with strpos()
| From: | aleksey dot v dot korzun at gmail dot com | Date: | Wed, 24 Oct 2012 23:26:37 +0000 |
| Subject: | Bug #63348 [Nab]: Unexpected behaviour with strpos() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174274@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63348&edit=1
ID: 63348
User updated by: aleksey dot v dot korzun at gmail dot com
Reported by: aleksey dot v dot korzun at gmail dot com
Summary: Unexpected behaviour with strpos()
Status: Not a bug
Type: Bug
Package: *Programming Data Structures
Operating System: *Nix
PHP Version: 5.3.18
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2012-10-24 23:15:20] 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 19:09:02] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63348&edit=1