ucfirst() Function Use in PHP 8.4 and PHP 8.5

The ucfirst() function behaves identically in PHP 8.4 and PHP 8.5. There are no version-specific changes for this function in either release. The most recent behavioral change dates back to PHP 8.2.0, which made the case conversion ASCII only and independent of the locale setting.

Function

ucfirst() returns a string with the first character of the input string converted to uppercase, leaving the rest of the string unchanged.

Signature:

ucfirst(string $string): string

Key Behavior:

  • ASCII Only: Since PHP 8.2, only characters in the range a(0x61) to z (0x7a) are converted. Accented characters like a will not be uppercased.
  • No Other Changes: It does not lowercase the rest of the string. If your input is "HELLO WORLD", the output remains “HELLO WORLD”.

Example

<?php
$text = "hello world";
$result = ucfirst($text);

echo $result; // Outputs: Hello world
?>

23 Views