-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement strrstr and transform strrchr into an alias of strrstr. #4064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -2852,6 +2853,7 @@ static const zend_function_entry basic_functions[] = { /* {{{ */ | |||
PHP_FE(str_pad, arginfo_str_pad) | |||
PHP_FALIAS(chop, rtrim, arginfo_rtrim) | |||
PHP_FALIAS(strchr, strstr, arginfo_strstr) | |||
PHP_FALIAS(strrchr, strrstr, arginfo_strstr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more alias, please 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure how to handle it otherwise as this is how strchr
was handled.
Yeap. |
Well I suppose I'll write this in the coming days |
Z_PARAM_STR(haystack) | ||
Z_PARAM_ZVAL(needle) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_BOOL(part) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Z_PARAM should be indented.
Looks reasonable implementation-wise, but yes, this will need an RFC. I think the main thing to sell here (and that I'm not at all sure about) is that having strrstr makes sense if we already have strrpos. It makes some sense from a consistency perspective, but apart from that we would never introduce this kind of function nowadays. |
I mean having slept on it I'm not even sure if it that wise to have it added to the language other than consistency like strrpos. I think I can come up with more cons than pros for this, also as @carusogabriel pointed out this would add another Alias to the language and the only reasonable way I can think of preventing it to stagnate for ages is to throw a deprecation warning to inform people to use strrstr instead but then this would have the odd consequence of only having strrchr deprecated but not strchr. Moreso it is a pretty niche usage, so will probably think about it some more and if I do write an RFC will probably list all the cons which come with it. But thanks for the feedbaack. |
Link to the RFC I wrote for this: https://wiki.php.net/rfc/implement-strrstr-for-consistency |
Withdrawing the RFC so closing PR. |
Implementing a reverse version of
strstr
as there is currently onlystrrchr
which only works on a single byte.before_needle
with true (?)strrchr
tests tostrrstr
(?)strristr
Would this need an RFC as this is technically a feature addition?