# [RFC] [VOTE] Prefix and Suffix Functions

- Thread: https://externals.io/message/130188
- Original archive: https://news-web.php.net/php.internals/130188
- Started by Barel on 2026-02-27T13:31:16+00:00
- Messages: 11
- RFC: Prefix and Suffix Functions (Declined) — https://externals.io/rfc/prefix_suffix_functions.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #130188 — Barel — 2026-02-27T13:31:16+00:00

URL: https://externals.io/message/130188#130188

Hi everyone,

This is to announce the opening of the vote for the Prefix and Suffix
Functions RFC

RFC: https://wiki.php.net/rfc/prefix_suffix_functions
Discussion thread: https://news-web.php.net/php.internals/129842

The vote will be open for 2 weeks (and a few hours), closing on March
13th at midnight UTC.

Cheers

Carlos

---

## #130192 — tim@bastelstu.be — 2026-02-27T14:44:42+00:00

URL: https://externals.io/message/130188#130192 · In reply to: #130188

Hi

Am 2026-02-27 14:31, schrieb Barel:
> This is to announce the opening of the vote for the Prefix and Suffix
> Functions RFC
> 
> RFC: https://wiki.php.net/rfc/prefix_suffix_functions
> Discussion thread: https://news-web.php.net/php.internals/129842
> 
> The vote will be open for 2 weeks (and a few hours), closing on March
> 13th at midnight UTC.

Thank you for quickly creating the separate thread. I also noticed that 
you forgot to move the RFC to the voting phase in the overview. I just 
did that:

https://wiki.php.net/rfc?do=diff&rev2%5B0%5D=1772199822&rev2%5B1%5D=1772203366&difftype=sidebyside

Please remember to also move it to the correct section once the vote 
finishes.

Best regards
Tim Düsterhus

---

## #130194 — Bob Weinand — 2026-02-27T16:24:09+00:00

URL: https://externals.io/message/130188#130194 · In reply to: #130188

Hey Carlos,


> Hi everyone,
>
> This is to announce the opening of the vote for the Prefix and Suffix 
> Functions RFC
>
> RFC: https://wiki.php.net/rfc/prefix_suffix_functions
> Discussion thread: https://news-web.php.net/php.internals/129842
>
> The vote will be open for 2 weeks (and a few hours), closing on March
> 13th at midnight UTC.
>
> Cheers
>
> Carlos


I like this RFC very much. I think every addition to the standard 
library needs to be well considered, but this one definitely crosses the 
bar.

Simple prefix and suffix operations are quite common - especially in 
scripting and manipulation of well-known strings.


While you certainly can write these with substr, it often either 
duplicates the string for the length or just hardcodes the length, both 
of which are equally ugly.
Sure, users can write helper functions for these, but I find below a 
certain size, users typically don't.

Thus I think this proposed change will lead to simpler and less 
error-prone code.


Bob

---

## #130195 — Larry Garfield — 2026-02-27T16:32:47+00:00

URL: https://externals.io/message/130188#130195 · In reply to: #130194

> Hey Carlos,
>
> 
> > […]
>
>
> I like this RFC very much. I think every addition to the standard 
> library needs to be well considered, but this one definitely crosses 
> the bar.
>
> Simple prefix and suffix operations are quite common - especially in 
> scripting and manipulation of well-known strings.
>
>
>
> While you certainly can write these with substr, it often either 
> duplicates the string for the length or just hardcodes the length, both 
> of which are equally ugly.
> Sure, users can write helper functions for these, but I find below a 
> certain size, users typically don't.
>
> Thus I think this proposed change will lead to simpler and less 
> error-prone code.

I know I personally would use the _ensure_() functions quite frequently in a project of mine.  Hence my yes vote.

Though I would also question why so many people are voting for $subject-last for the secondary vote.

--Larry Garfield

---

## #130196 — Bob Weinand — 2026-02-27T16:42:06+00:00

URL: https://externals.io/message/130188#130196 · In reply to: #130195

Hey Larry,


> Though I would also question why so many people are voting for $subject-last for the secondary vote.
>
> --Larry Garfield


The two-argument variants are consistent with e.g. addcslashes (one 
subject operated on with an argument) - so that's perfectly consistent.

Then for replacing, you want consistency with str_replace, and 
preg_replace and such.


Bob

---

## #130197 — Ilija Tovilo — 2026-02-27T16:47:40+00:00

URL: https://externals.io/message/130188#130197 · In reply to: #130196

>
> Hey Larry,
>
> 
> > […]
>
> The two-argument variants are consistent with e.g. addcslashes (one
> subject operated on with an argument) - so that's perfectly consistent.
>
> Then for replacing, you want consistency with str_replace, and
> preg_replace and such.

Maybe consistently inconsistent. ;) In my opinion, it's much better to
not keep repeating the same mistake, pick a standard and stick with
it. Subject-first always works. I wouldn't think many people want to
internalize the placement of the subject based on the kind of string
replacement function.

Ilija

---

## #130198 — Kamil Tekiela — 2026-02-27T16:55:37+00:00

URL: https://externals.io/message/130188#130198 · In reply to: #130197

>
> 
> > […]
>
> Maybe consistently inconsistent. ;) In my opinion, it's much better to
> not keep repeating the same mistake, pick a standard and stick with
> it. Subject-first always works. I wouldn't think many people want to
> internalize the placement of the subject based on the kind of string
> replacement function.
>
> Ilija

I think $subject should be first because these functions align with
other str_prefix_* functions. If the names were inverted, i.e.
str_ensure_prefix, then I would vote for $subject to be last because
str_replace and str_replace_suffix are more aligned.

---

## #130199 — Andrey Andreev — 2026-02-27T18:09:28+00:00

URL: https://externals.io/message/130188#130199 · In reply to: #130197

> 
> > […]
> $subject-last for the secondary vote.
> > […]
>
> Maybe consistently inconsistent. ;) In my opinion, it's much better to
> not keep repeating the same mistake, pick a standard and stick with
> it. Subject-first always works. I wouldn't think many people want to
> internalize the placement of the subject based on the kind of string
> replacement function.


Indeed, alternating parameter order based on the type of operation would be
just frustrating.
Consistency with existing functions is nice in principle, but not all
historic precedents are good.

---

## #130200 — Christian Schneider — 2026-02-27T21:28:00+00:00

URL: https://externals.io/message/130188#130200 · In reply to: #130188

Am 27.02.2026 um 14:31 schrieb Barel <barel.barelon@gmail.com>:
> This is to announce the opening of the vote for the Prefix and Suffix Functions RFC
> 
> RFC: https://wiki.php.net/rfc/prefix_suffix_functions
> Discussion thread: https://news-web.php.net/php.internals/129842

My reason to vote no was that
a) it is sort of a matrix of functions (prefix|suffix x ensure|remove|replace) a doing something very similar
b) there are several downsides to these specific implementations

The downsides I see at a first glance:
- case sensitive: str_suffix_replace(".jpeg", ".jpg", $filename) does not work with "Image.JPEG"
- *_ensure doesn't handle multiples: str_suffix_ensure($path, '/') does not handle "/api//"

This leads me to the conclusion that I'd probably stick to the old-school use of preg_replace which handles *all* the things these functions try to solve.
And while I agree that regular expressions are a bit harder to read they (to me) are simple enough while not having these downsides.

E.g. I would rewrite
	$file = str_suffix_replace('.jpeg', '.jpg', $file);
as
	$file = preg_replace('#\.jpeg$#i', '.jpg', $file);	# Case insentive, easily extended also handle jpe and jfif

And instead of
	$path = str_suffix_ensure($path, '/');
I would write
	$path1 = preg_replace('#/*$#', '/', $path, 1);	# Ensure one single slashes at the end
or maybe even
	$path = preg_replace('#/+#', '/', "$path/");	# Also normalizes all multiple slashes in the path

Side-note: Regular expressions handle all the stuff described in the Future Scope section.

Some people like long and descriptive special functions for (depending on the context) common cases but I realized that I often prefer being able to reuse powerful functionality instead of having to guess if a specialized function might exists even with modern dev environments make finding the right function easier. YMMV.

Regards,
- Chris

---

## #130204 — Ben Ramsey — 2026-02-27T22:44:43+00:00

URL: https://externals.io/message/130188#130204 · In reply to: #130195

> I know I personally would use the _ensure_() functions quite frequently in a project of mine.  Hence my yes vote.
> 
> Though I would also question why so many people are voting for $subject-last for the secondary vote.
> 
> --Larry Garfield


I changed my mind on the subject placement due to others' arguments 
about being consistent with str_replace, str_ireplace, preg_replace, 
preg_replace_callback, mb_ereg_replace, mb_ereg_replace_callback, and 
mb_eregi_replace.

The odd one out among these is substr_replace.

Cheers,
Ben

---

## #130305 — Barel — 2026-03-13T07:00:32+00:00

URL: https://externals.io/message/130188#130305 · In reply to: #130188

Hi,

The vote for this RFC has finished. Even though there were more positive
than negative votes, the number of positive votes did not reach the needed
2/3 majority, so the RFC has been declined

I would like to thank everyone who voted, everyone who participated in the
discussion and everyone who helped me shape the RFC

Cheers

Carlos

RFC: https://wiki.php.net/rfc/prefix_suffix_functions
Discussion thread: https://news-web.php.net/php.internals/129842
