What’s New in PHP 8.1? Enumerations, Read‑only Properties, Fibers and More

The PHP 8.1 release introduces enumerations, first‑class read‑only properties, the never return type, array_is_list, Fibers and other enhancements while also outlining deprecations and the newly formed PHP Foundation that supports the language’s future development.

21CTO
21CTO
21CTO
What’s New in PHP 8.1? Enumerations, Read‑only Properties, Fibers and More

PHP 8.1 Release Overview

After 26 years of evolution and strong competition, PHP remains essential for most websites worldwide. On November 25 the PHP development team officially released PHP 8.1, bringing a host of practical features requested by developers.

Enumerations (enum)

PHP 8.1 adds the enum keyword, allowing developers to declare a fixed set of values similar to enums in C or Python. Enums are declared with syntax resembling classes or interfaces and can be backed by strings or integers, extend classes, and implement interfaces, improving code readability.

First‑class Read‑only Properties

PHP 8.1 introduces read‑only properties that can be declared public and initialized only once, either at the point of declaration or in the constructor. Any subsequent modification triggers an exception, ensuring immutable state for those properties.

Never Return Type

The new never return type can be used for functions that never return a value because they always throw an exception or terminate the request, allowing static analysis tools to understand such code paths.

array_is_list Function

A new array_is_list function checks whether an array’s keys are consecutive integers starting from zero, simplifying validation of list‑like arrays.

Other Enhancements

Additional improvements include a core implementation of fsync, a method to test whether a constant is final, and the introduction of Fibers. Fibers provide non‑blocking execution contexts similar to Ruby’s fibers, complementing existing async libraries such as Swoole.

Deprecations and Warnings

PHP 8.1 deprecates several practices: passing null to non‑nullable scalar parameters and implicit conversion of non‑integer‑compatible floats to integers now emit warning‑level errors.

PHP Foundation

The PHP Foundation, a non‑profit organization, was created to ensure continued development by providing salaries for core contributors. The RFC process remains unchanged, with decisions staying within the PHP Internals community. Founding members include Acquia, Automattic, Craft CMS, JetBrains, Laravel, PrestaShop, Private Packagist, Symfony, Todeways and Zend.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

backend-developmentreadonly-propertiesFibersenumerationsphp-8.1
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.