On 2026-01-16 21:16, Barel wrote:

function add_prefix(string $source, string $prefix): string
function add_suffix(string $source, string $suffix): string

Add a prefix or suffix to a string *only if the string does not yet have it*

Hi,

As the functions do not always *add* a prefix, I'd suggest to consider names like `ensure_prefix` or `enforce_prefix` instead.

Something like `ensure_str_starts_with` or `ensure_starts_with` would be a nicer fit with the `str_starts_with`, but then it doesn't rhyme with the other prefix/suffix functions that well.

Otherwise I can only say that I've had to solve the same tasks in multiple projects, so I'd enjoy such functions being available in PHP itself.

BR,
Juris

Reply via email to