PHP 8.1 : What’s New? 

If you are reading this you probably are curious to know what the new features are in the new PHP version 8.1. 

It has been released on November 25, 2021 and it includes several new performance improvements and deprecations. 

Let’s get right into it. 

Here is an overview of the many new features: 

  • Pure Intersection Types
  • Enums
  • The never Return Type
  • Fibers
  • New readonly Properties
  • Define final Class Constants
  • New fsync() and fdatasync() Functions
  • New array_is_list() Function
  • New Sodium XChaCha20 Functions
  • New IntlDatePatternGenerator Class
  • Support for AVIF Image Format
  • New $_FILES: full_path Key for Directory Uploads
  • Array Unpacking Support for String-Keyed Arrays
  • Explicit Octal Numeral Notation
  • MurmurHash3 and xxHash Hash Algorithms Support
  • DNS-over-HTTPS (DoH) Support
  • File Uploads from Strings with CURLStringFile
  • New MYSQLI_REFRESH_REPLICA Constant
  • Performance Improvements with Inheritance Cache
  • First-Class Callable Syntax

If you are not too familiar with the development environment of PHP, It could seem like a lot of foreign words.

However, if you have a website running the new PHP version or if you are planning to, you will probably be interested in the performance benefits that are added in this new version. 

So let’s talk about performance improvements. 

Inheritance Cache

Let’s talk about Inheritance Cache. This is a new feature added to Opcache that will eliminate PHP class inheritance overhead. The new Inheritance Caches links all dependent classes and stores the results in opcache shared memory. This will avoid relinking classes in each request. Thus, reducing the amount of instructions required in requests. 

More performance improvements 

PHP.NET has shared a Symphony Demo App showing the improvements in speed compared to previous versions and they are quite impressive.

On top of the inheritance cache, these are the new performance related features in this version :

  • JIT backend for ARM64 (AArch64)
  • Fast class name resolution (avoid lowercasing and hash lookup)
  • timelib and ext/date performance improvements
  • SPL file-system iterators improvements
  • serialize/unserialize optimizations
  • Some internal functions optimization (get_declared_classes(), explode(), strtr(), strnatcmp(), dechex())
  • JIT improvements and fixes

If you are curious about the are classes, interfaces and new addition to the development side of PHP 8.1, you will enjoy the following features as well. 

Enums 

Finally! Enums are here. No more setting up constants to play the role of enums.

Readonly Properties

We can also create properties that cannot be changed once initialized. 

First-class Callable Syntax

It’s now easy to retrieve the reference to any function. 

Never return type

It’s super helpful to use in functions that always throw or exit. It indicates that it will not return a value and will either throw an exception or end the script’s execution with a call of die(), exit(), trigger_error(), or something similar.

And there is much more !

If you are curious to see all the features and new additions to the PHP version, take a look at the release update on PHP : https://www.php.net/releases/8.1/en.php

Leave a Reply