# RFC: Multibyte for ucfirst and lcfirst functions

- Status: Implemented (PHP 8.4)
- Authors: Author: Yuya Hamada(https://github.com/youkidearitai), youkidearitai@gmail.com
- Date: 2024-01-16
- Version: 0.1.2
- Original: https://wiki.php.net/rfc/mb_ucfirst
- Page: https://externals.io/rfc/mb_ucfirst
- 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

## Votes

### Add mb_ucfirst and mb_lcfirst functions (closed)

Yes: 15 · No: 0

Voters: ashnazg (Yes), beberlei (Yes), bwoebi (Yes), crell (Yes), dams (Yes), devnexen (Yes), galvao (Yes), kguest (Yes), kocsismate (Yes), nielsdos (Yes), saki (Yes), sergey (Yes), thekid (Yes), tstarling (Yes), weierophinney (Yes)

## Discussions on the mailing list

- [\[RFC\] \[Under Discussion\] mb_ucfirst and mb_lcfirst](https://externals.io/message/122171.md) — started on 2024-01-18, 3 messages
- [\[VOTE\]\[RFC\] mb_ucfirst and mb_lcfirst functions](https://externals.io/message/122271.md) — started on 2024-02-02, 15 messages

---

## Introduction

PHP does not have a multibyte equivalent of ucfirst, lcfirst functions. It is possible to get close enough behavior below:

```
function mb_ucfirst(string $str, ?string $encoding = null): string
{
    return mb_convert_case(mb_substr($str, 0, 1, $encoding), MB_CASE_TITLE, $encoding) . mb_substr($str, 1, null, $encoding);
}
```

```
function mb_lcfirst(string $str, ?string $encoding = null): string
{
    return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, null, $encoding);
}
```

However adding a pre-built functions to do this will implobe the readability and clarify of PHP code. And it will standardize how it is done as it can be tricky.

## Proposal

Add mb\_ucfirst function, mb\_lcfirst function.

```
function mb_ucfirst(string $string, ?string $encoding = null): string
```

The first character in mb\_ucfirst uses Unicode title case.

```
function mb_lcfirst(string $string, ?string $encoding = null): string
```

From what I've researched with Unicode, it may not behave as expected in some languages. In that case, please deal with it in userland.

For example, In Vietnamese, the first letter is not always capitalized.

- ngày Quốc khánh 2-9 (September 2nd National Day)
- tiếng Nhật (Japanese)

Another example, In Georgian should uses title case.

- mb\_strtoupper(“აბგ”) (ani bani gani, U+10D0 U+10D1 U+10D2) -&gt; ᲐᲑᲒ(U+1C90 U+1C91 U+1C92)
- mb\_strtoupper(“ǉ”)(U+01C9) -&gt; “Ǉ” (U+01C7)

Correct case.

- mb\_ucfirst(“აბგ”) -&gt; “აბგ” (U+10D0 U+10D1 U+10D2)
- mb\_ucfirst(“ǉ”) -&gt; “ǈ” (U+01C9 -&gt; U+01C8)

## Backward Incompatible Changes

This could break a function existing in userland with the same name.

## Proposed PHP Version(s)

next PHP 8.x

## RFC Impact

### To SAPIs

To SAPIs Will add the aforementioned functions to all PHP environments.

### To Existing Extensions

Adds mb\_ucfirst(), mb\_lcfirst() to the mbstring extension.

### To Opcache

No effect.

### New Constants

No new constants.

### php.ini Defaults

No changed php.ini settings.

## Open Issues

<https://github.com/php/php-src/issues/13075>

## Future Scope

This section details areas where the feature might be improved in future, but that are not currently proposed in this RFC.

## Voting

**Vote: Add mb\_ucfirst and mb\_lcfirst functions** — Yes: 15 · No: 0 (closed)

## Implementation

<https://github.com/php/php-src/pull/13161>

## Rejected Features

Keep this updated with features that were discussed on the mail lists.
