php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66563 strrchr ignores offset parameter
Submitted: 2014-01-23 22:32 UTC Modified: 2014-01-24 01:55 UTC
From: myselfasunder at gmail dot com Assigned:
Status: Open Package: Strings related
PHP Version: 5.4.24 OS: OS X 10.9.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: myselfasunder at gmail dot com
New email:
PHP Version: OS:

 

 [2014-01-23 22:32 UTC] myselfasunder at gmail dot com
Description:
------------
The documentation indicates that the offset describes the number of characters from the front of the string, and that the search will -start- at the offset and move toward the beginning. 

However, the offset seems to be ignored.

Test script:
---------------
$buffer = '01234567890123456789';
var_dump(strrpos($buffer, '0', 5));


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

Actual result:
--------------
int(10)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-23 23:19 UTC] requinix@php.net
-Type: Bug +Type: Documentation Problem
 [2014-01-23 23:19 UTC] requinix@php.net
The offset controls the start or end point for the search: positive offset is the ending point, negative offset is the starting point (from the end). So $offset=5 means to search from the end towards the beginning as usual but to stop at offset 5, and $offset=-5 means to search from offset ending-5 to the beginning.

According to that, the documentation should be changed to read like
 >offset
-> If specified, search will start this number of characters counted from the
+> If specified, search will end this number of characters counted from the
 > beginning of the string. If the value is negative, search will instead start
 > from that many characters from the end of the string, searching backwards.
 [2014-01-24 01:55 UTC] myselfasunder at gmail dot com
Confirmed. Thank you.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 13:01:27 2019 UTC