# [RFC] grapheme_str_pad()

- Thread: https://externals.io/message/132995
- Original archive: https://news-web.php.net/php.internals/132995
- Started by Chris Abner Herrera Navarro on 2026-11-03T23:01:51+00:00
- Messages: 5
- RFC: grapheme_str_pad() (Under discussion) — https://externals.io/rfc/grapheme_str_pad.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

---

## #132995 — Chris Abner Herrera Navarro — 2026-11-03T23:01:51+00:00

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

Hi internals,

I'd like to start the discussion on a new RFC:
https://wiki.php.net/rfc/grapheme_str_pad

It proposes grapheme_str_pad(), the grapheme cluster counterpart of `str_pad()` and `mb_str_pad()`, following the Future Scope of the mb_str_pad
RFC. The length is counted in grapheme clusters, so text in NFD, kana with
a combining dakuten, Indic scripts and emoji sequences are padded to the
same visible length as their single code point equivalents, and the padding
string is only cut on grapheme cluster boundaries.

Semantics and errors mirror `mb_str_pad()`. For ASCII input the result is
identical to `str_pad()`.

Implementation: https://github.com/php/php-src/pull/25179

Thanks,
Chris Abner Herrera Navarro

---

## #132996 — tim@bastelstu.be — 2026-11-04T13:58:15+00:00

URL: https://externals.io/message/132995#132996 · In reply to: #132995

Hi


> I'd like to start the discussion on a new RFC:
> https://wiki.php.net/rfc/grapheme_str_pad
> 
> […]
> 
> Semantics and errors mirror `mb_str_pad()`. For ASCII input the result is
> identical to `str_pad()`.

Thank you for your RFC. Padding graphemes to a given length makes sense 
to me and the RFC clearly follows the established pattern of mirroring 
the string (bytestring) and mbstring (codepoint) functionality. I don't 
have any comments, the RFC includes exactly what I expected to see.

Best regards
Tim Düsterhus

---

## #132997 — youkidearitai — 2026-11-04T14:31:58+00:00

URL: https://externals.io/message/132995#132997 · In reply to: #132995

2026年11月4日(水) 8:05 Chris Abner Herrera Navarro <chrisabner@hotmail.com>:
>
> Hi internals,
>
> I'd like to start the discussion on a new RFC:
> https://wiki.php.net/rfc/grapheme_str_pad
>
> It proposes grapheme_str_pad(), the grapheme cluster counterpart of
> `str_pad()` and `mb_str_pad()`, following the Future Scope of the mb_str_pad
> RFC. The length is counted in grapheme clusters, so text in NFD, kana with
> a combining dakuten, Indic scripts and emoji sequences are padded to the
> same visible length as their single code point equivalents, and the padding
> string is only cut on grapheme cluster boundaries.
>
> Semantics and errors mirror `mb_str_pad()`. For ASCII input the result is
> identical to `str_pad()`.
>
> Implementation: https://github.com/php/php-src/pull/25179
>
> Thanks,
> Chris Abner Herrera Navarro

Hi

Thank you very much for your RFC.
It seems good to me.
And thank you for understanding grapheme functions.

Regards
Yuya

-- 
---------------------------
Yuya Hamada (tekimen)
- https://tekitoh-memdhoi.info
- https://github.com/youkidearitai

---

## #133000 — Chris Abner Herrera Navarro — 2026-11-04T21:21:56+00:00

URL: https://externals.io/message/132995#133000 · In reply to: #132997

Hi Tim, Yuya,

> It seems good to me.

Thank you both for taking a look.

I've updated the RFC to v0.2. Nothing changes in behaviour, these are
clarifications that came out of the review on the PR:

- $pad_string and $pad_type are only checked when padding is needed,
  like in `mb_str_pad()`. Otherwise $string is returned unchanged.
- The RFC said invalid UTF-8 is handled like in `grapheme_strlen()`, but
  `grapheme_strlen()` returns null there, not false. It now points to
  `grapheme_substr()` and `grapheme_strpos()` instead.
- The result has exactly $length grapheme clusters as long as the
  padding is made of complete clusters. A fragment like a lone
  combining mark can merge with the text next to it, the same way
  grapheme_strlen($a . $b) can be less than the sum of both lengths.

The implementation now also respects memory_limit for very large
results, and fills the padding faster.

Regards,
Chris Abner Herrera Navarro

---

## #133090 — Chris Abner Herrera Navarro — 2026-11-12T16:27:13+00:00

URL: https://externals.io/message/132995#133090 · In reply to: #133000

Hi internals,

There has been no further feedback since v0.2, so this is the intent
to vote for the grapheme_str_pad() RFC.

I plan to open the vote on Wednesday, 18 November 2026, at 16:00 UTC.
It will close on Wednesday, 2 December 2026, at 16:00 UTC.

There is one primary vote. It needs a 2/3 majority.

RFC: https://wiki.php.net/rfc/grapheme_str_pad
Discussion thread: https://news-web.php.net/php.internals/132995

Regards,
Chris Abner Herrera Navarro
