php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50710 stripos returns FALSE for empty string used as needle
Submitted: 2010-01-10 09:28 UTC Modified: 2010-01-11 09:06 UTC
From: miklcct at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.3.1 OS: Ubuntu 9.10
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: miklcct at gmail dot com
New email:
PHP Version: OS:

 

 [2010-01-10 09:28 UTC] miklcct at gmail dot com
Description:
------------
The function stripos() returns FALSE when a empty string is used.
Consider the example below, an empty string is used and it is found at position 0. It is misleading (at least theoretically) that an empty string is not found inside another string.

Reproduce code:
---------------
<?php
var_dump(stripos('test', 'te'));
var_dump(stripos('test', 't'));
var_dump(stripos('test', ''));
var_dump(stripos('test', 'es', 1));
var_dump(stripos('test', 'e', 1));
var_dump(stripos('test', '', 1));
var_dump(stripos('test', '', 2));
var_dump(stripos('', ''));
?>


Expected result:
----------------
int(0)
int(0)
int(0)
int(1)
int(1)
int(1)
int(2)
int(0)

Actual result:
--------------
int(0)
int(0)
bool(false)
int(1)
int(1)
bool(false)
bool(false)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-10 09:34 UTC] rasmus@php.net
By that logic shouldn't it always return true then?  There is an empty 
string everywhere in a string.  Before the first char, between each 
char, etc.  Not sure that is a useful result though.
 [2010-01-10 22:37 UTC] jani@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

,
 [2010-01-11 09:06 UTC] miklcct at gmail dot com
This is not only for stripos, it is for the whole str*pos family and the documentation specifies that "If needle is not found, str*pos() will return boolean FALSE" but the fact is the empty string can be found in any string
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 00:01:32 2024 UTC