Hi,
I would like to open the discussion on my proposal to add new functions to
process prefixes and suffixes
This is the link to the RFC:
https://wiki.php.net/rfc/prefix_suffix_functions
This is the link to the proposed implementation:
https://github.com/php/php-src/pull/20953
Thanks!!
Carlos
Hi
Am 2026-01-22 10:10, schrieb Barel:
I would like to open the discussion on my proposal to add new functions
to
process prefixes and suffixesThis is the link to the RFC:
https://wiki.php.net/rfc/prefix_suffix_functions
Please don't forget to move it to the correct section in the overview
at: https://wiki.php.net/rfc - and to add a link to the discussion
thread archives to the “References” section. The “pre-RFC” thread is
probably also to link there:
https://news-web.php.net/php.internals/129767
Best regards
Tim Düsterhus
Following a comment by Tim Düsterhus (thanks!) and another comment in the
PR, I have inverted the order of the parameters in the ensure and remove
functions, so that they follow the parameter order in related functions
like str_contains() and str_starts_with()
Cheers
Carlos
Hi
Am 2026-01-22 10:10, schrieb Barel:
I would like to open the discussion on my proposal to add new functions
to
process prefixes and suffixesThis is the link to the RFC:
https://wiki.php.net/rfc/prefix_suffix_functionsPlease don't forget to move it to the correct section in the overview
at: https://wiki.php.net/rfc - and to add a link to the discussion
thread archives to the “References” section. The “pre-RFC” thread is
probably also to link there:
https://news-web.php.net/php.internals/129767Best regards
Tim Düsterhus
Hi
Am 2026-01-22 19:28, schrieb Barel:
Following a comment by Tim Düsterhus (thanks!) and another comment in
the
PR, I have inverted the order of the parameters in the ensure and
remove
functions, so that they follow the parameter order in related functions
likestr_contains()andstr_starts_with()
Thank you. I have given the RFC another look and have some polishing
comments:
-
In the “Exact semantics (per function)” example it would probably be
easier to understand if you would provide a userland implementation.
Folks are already used to reading PHP and there is no ambiguity about
the proposed behavior then. As a benefit, the implementation from the
RFC would directly be usable as a polyfill, e.g. for use in
https://github.com/symfony/polyfill. The previous “array_find” RFC might
be a good example here: https://wiki.php.net/rfc/array_find -
In the “Backwards Incompatible Changes” section: Can you please
perform some research for a rough number estimation? e.g. using GitHub's
code search.
Another thing I realized is the interaction between the _replace
functions and PFA: It can be used as an (inefficient?) way of creating a
concat as a function handle: $concat = str_prefix_replace("", ?, ?);
(with suffix_replace being a reverse concat).
Best regards
Tim Düsterhus
Hi
Am 2026-01-22 19:28, schrieb Barel:
Following a comment by Tim Düsterhus (thanks!) and another comment in
the
PR, I have inverted the order of the parameters in the ensure and
remove
functions, so that they follow the parameter order in related functions
likestr_contains()andstr_starts_with()Thank you. I have given the RFC another look and have some polishing
comments:
In the “Exact semantics (per function)” example it would probably be
easier to understand if you would provide a userland implementation.
Folks are already used to reading PHP and there is no ambiguity about
the proposed behavior then. As a benefit, the implementation from the
RFC would directly be usable as a polyfill, e.g. for use in
https://github.com/symfony/polyfill. The previous “array_find” RFC might
be a good example here: https://wiki.php.net/rfc/array_findIn the “Backwards Incompatible Changes” section: Can you please
perform some research for a rough number estimation? e.g. using GitHub's
code search.
Another thing I realized is the interaction between the
_replace
functions and PFA: It can be used as an (inefficient?) way of creating a
concat as a function handle:$concat = str_prefix_replace("", ?, ?);
(with suffix_replace being a reverse concat).Best regards
Tim Düsterhus
Tim, thanks for your suggestions, I updated the RFC
Cheers
Carlos