DEV Community

Cover image for PHP 8.5: The Version That Will Actually Makes Life Easier

PHP 8.5: The Version That Will Actually Makes Life Easier

Muhammad Usman on September 24, 2025

The Developer-Friendly Upgrade You’ve Been Waiting For PHP 8.5 is out soon, and honestly, it’s one of those releases that makes me excit...
Collapse
 
homeless-coder profile image
HomelessCoder

Finally, array_first and array_last! 🙌 Great article, @web_dev-usman
I'm trying to wrap my head around the implications of closures in constants. My biggest concern is that it might encourage improper usage, leading to code with undefined or leaky boundaries.

Collapse
 
xwero profile image
david duymelinck

Every feature has the possibility of improper usage.

I think the example is not the most useful one. The more useful example is when the closure is paired with an attribute.
Instead of having to create a one-of function or instance somewhere in the application, it is now possible to do it as an attribute argument.

final class Locale
{
    #[Validator\Custom(static function (string $languageCode): bool {
        return \preg_match('/^[a-z][a-z]$/', $languageCode);
    })]
    public string $languageCode;
}
Enter fullscreen mode Exit fullscreen mode

you can see more examples here.

Collapse
 
web_dev-usman profile image
Muhammad Usman

Thanks for your feedback.

Collapse
 
web_dev-usman profile image
Muhammad Usman

Thanks...

Collapse
 
prime_1 profile image
Roshan Sharma

Nice post! PHP 8.5 looks great, pipe operator, array helpers, and better error stack traces will make life way easier.

Collapse
 
web_dev-usman profile image
Muhammad Usman

Glad you liked it.

Collapse
 
pau1phi11ips profile image
Paul Phillips

It's pretty obvious from the examples that this has been copied from one of Nuno's posts. It would be nice to give him credit.

Collapse
 
web_dev-usman profile image
Muhammad Usman

Of course, I took inspiration from different people in my writing. This is called research of topics.

Collapse
 
web_dev-usman profile image
Muhammad Usman

PHP 8.5 is bringing some amazing quality-of-life updates.
Which one excites you the most?

Collapse
 
nd3w profile image
nd3w • Edited

array_first and array_last, surprisingly I can't think when I need this kind of functions, but it's nice to have.

Collapse
 
xwero profile image
david duymelinck • Edited

The only use case i can think of is when you need to keep the array as is, but you want the first or last value to prepend or append the array.

I think I is more to have a value equivalent for the array_key_first and array_key_last functions. It creates a consistency a lot of people think is lacking in PHP. When new array functions are added there is a key and a value equivalent, like array_find_key and array_find. Of course the old key value equivalents will stay as they are, like key_exists and in_array.

Collapse
 
web_dev-usman profile image
Muhammad Usman

“Closures in Constant Expressions” Hell Yeah!

Collapse
 
vibiz profile image
Vibiz

Good!