Take the State of PHP 2026 Survey →

Multibyte for ucfirst and lcfirst functions View as Markdown

Implemented (PHP 8.4)
Authors
Author: Yuya Hamada(https://github.com/youkidearitai), youkidearitai@gmail.com
Date
2024-01-16
Version
0.1.2
Source
wiki.php.net/rfc/mb_ucfirst

Vote

Add mb_ucfirst and mb_lcfirst functions closed
Yes
15
No
0
15 voters
ashnazg Yes 2024-03-06 19:51
beberlei Yes 2024-02-24 19:02
bwoebi Yes 2024-03-03 22:52
crell Yes 2024-02-23 15:09
dams Yes 2024-03-03 15:49
devnexen Yes 2024-02-29 08:09
galvao Yes 2024-02-24 08:18
kguest Yes 2024-03-05 14:19
kocsismate Yes 2024-02-29 20:52
nielsdos Yes 2024-02-21 10:50
saki Yes 2024-02-23 04:25
sergey Yes 2024-02-29 09:26
thekid Yes 2024-03-01 20:10
tstarling Yes 2024-02-21 01:24
weierophinney Yes 2024-02-21 21:51

Discussions on the mailing list

[RFC] [Under Discussion] mb_ucfirst and mb_lcfirst
by youkidearitai · 3 messages
[VOTE][RFC] mb_ucfirst and mb_lcfirst functions
by youkidearitai · 15 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:50 UTC

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) -> ᲐᲑᲒ(U+1C90 U+1C91 U+1C92)
  • mb_strtoupper(“lj”)(U+01C9) -> “LJ” (U+01C7)

Correct case.

  • mb_ucfirst(“აბგ”) -> “აბგ” (U+10D0 U+10D1 U+10D2)
  • mb_ucfirst(“lj”) -> “Lj” (U+01C9 -> 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.