php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52197 confusing description of return value 'strpos()'
Submitted: 2010-06-27 17:55 UTC Modified: 2010-06-27 18:47 UTC
From: gearond at sbcglobal dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: ubuntu
Private report: No CVE-ID: None
 [2010-06-27 17:55 UTC] gearond at sbcglobal dot net
Description:
------------
I originally submitted the material below this paragraph, but it has been discussed before - WITH the exception of the "" return value. There needs to be some description of circumstances under which "" gets returned. Otherwise it's a random response, and we programmers like finite responses :-)

The function prototype on the document page says it returns an INT. The pink warning box at the bottom says it might return INT, BOOL, "". The return type should be set to MIXED.

And in what case, given the decscription of this function's operation, would it return an empty string?

Test script:
---------------
Not needed

Expected result:
----------------
n/a

Actual result:
--------------
n/a

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-27 18:47 UTC] bjori@php.net
-Status: Open +Status: Bogus
 [2010-06-27 18:47 UTC] bjori@php.net
It will never return empty string.

It can however return int(0) and bool(false) which is what the note is about.
Never do if(strpos($haystack, $needle)) {} to check if the $needle is in the 
$haystack.

This is clearly demonstrated by the examples on the page.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC