rfc:implement-strrstr-for-consistency

PHP RFC: Implement strrstr counterpart to strstr for consistency

Introduction

Implement strrstr (and possibly strristr) for consistency with the strpos string functions family.

Currently there exist no “proper” counter part to the strstr (and stristr) standard string function. There exist strrchr however it does not have the same signature as strstr nor strchr as strchr is an alias of strstr, nor does it provide the same features.

Proposal

Implement strrstr and strristr (?) in PHP 7.4 with the same features as strstr, meaning that the $needle parameter can accept multiple characters and add a boolean parameter $before_needle which has a default value of false.

Pros

  • Consistency within the standard library
  • Feature built-in to the language

Cons

  • More “bloat” in the global namespace
  • Follows an old naming scheme
  • Adds a function alias to the language
  • Easily implemented in userland

Backward Incompatible Changes

None

Proposed PHP Version(s)

Next minor i.e. PHP 7.4.

Open Issues

How to handle the newly created alias.

Proposed Voting Choices

2/3 Majority for adding strrstr (and possibly strristr after discussion).

Patches and Tests

GitHub PR #4064

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged into
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)

References

Announcement on internals: https://externals.io/message/105997

rfc/implement-strrstr-for-consistency.txt · Last modified: 2019/07/03 10:11 by girgias