PHP 8.1 is coming — and it already promises to be one of the best releases

The coming version of PHP, scheduled for November 2021, is already packed with a lot of super exciting features.

Alexandre Daubois
Geek Culture
Published in
4 min readJun 10, 2021

--

Photo by Tianyi Ma on Unsplash

String-keyed array unpack

A simple operation, which wasn’t allowed until PHP 8.1. A code snippet worth a thousand words, here is what you’ll be able to do now:

This seems super simple, but you were only allowed to this with arrays with integer keys. As soon as you tried it with string-keyed arrays, you would get a fatal error.

Note that this new feature produce the exact same result as array_merge, which you can use with string-keyed array on any PHP version where it is available.

RFC: https://wiki.php.net/rfc/array_unpacking_string_keys

IntlDatePatternGenerator

Internationalization of dates and format localization has always been a bit of a pain in PHP. This time is nearly over, and PHP 8.1 will be shipped with the new IntlDatePatternGenerator class.

To be short, the purpose of this class is to guess which format will suit the most to a given locale. To illustrate this, I’ll take the example given in the RFC:

As you can see, we’re going to have have way less headache dealing with date formats and localization. Give getBestPattern your locale and the “skeleton” you want it to format. Then by calling IntlDateFormatter, you’ll get your formatted date for your locale. I love it.

RFC: https://wiki.php.net/rfc/intldatetimepatterngenerator

Enumerations

--

--

Alexandre Daubois
Geek Culture

Lead Developer at Wanadev // Open-source contributor