Skip to content

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Apr 23, 2019

Implementing a reverse version of strstr as there is currently only strrchr which only works on a single byte.

  • Add more tests for before_needle with true (?)
  • Rename strrchr tests to strrstr (?)
  • Implement a case insensitive version named strristr

Would this need an RFC as this is technically a feature addition?

@Girgias Girgias changed the base branch from master to PHP-7.4 April 23, 2019 20:33
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more alias, please 😢

Copy link
Member Author

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.

@carusogabriel
Copy link
Contributor

Would this need an RFC as this is technically a feature addition?

Yeap.

@Girgias
Copy link
Member Author

Girgias commented Apr 23, 2019

Would this need an RFC as this is technically a feature addition?

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)
Copy link
Member

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.

@nikic
Copy link
Member

nikic commented Apr 24, 2019

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.

@Girgias
Copy link
Member Author

Girgias commented Apr 24, 2019

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.

@cmb69 cmb69 added the RFC label Apr 24, 2019
@Girgias
Copy link
Member Author

Girgias commented Jun 20, 2019

Link to the RFC I wrote for this: https://wiki.php.net/rfc/implement-strrstr-for-consistency

@Girgias
Copy link
Member Author

Girgias commented Jul 3, 2019

Withdrawing the RFC so closing PR.

@Girgias Girgias closed this Jul 3, 2019
@Girgias Girgias deleted the add-strrstr branch July 3, 2019 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants