hhvm
hhvm copied to clipboard
RFC: Replacement for `Str\search_last()`, replacing `$offset` with `$length`
Summary: Explanation in code
Implementation is just placeholder that is clear about behavior. Not for landing.
Current behavior does not match the documentation in PHP or HHVM
Related: https://bugs.php.net/bug.php?id=73913 https://www.php.net/manual/en/function.strrpos.php
Differential Revision: D29153162
This pull request was exported from Phabricator. Differential Revision: D29153162
Positive offsets
Rare, can be emulated with:
$pos = Str\search_last($a, $b);
if ($pos < $offset) {
$pos = null;
}
Negative offsets
Extremely rare. Can be converted to a length with
$length = strlen($haystack) + min(strlen($needle) + $offset, 0)
Another approach would be to accept both offset and length parameters (this would be consistent with one of the ICU indexOf/lastIndexOf overrides), with offset having no effect other than where to start/stop looking; negative offsets could still be supported, but an offset of -5 would literally mean 'only look in the last 5 bytes'; a length of -5 could mean 'don't look at the last 5 bytes'
Hi @fredemmott!
Thank you for your pull request.
We require contributors to sign our Contributor License Agreement, and yours needs attention.
You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!