What’s New in PHP 8.1? Enums, Read‑only Properties, Async & Serverless Insights

The article reports Alexa’s shutdown and TIOBE’s shift to Similarweb, highlights the February TIOBE Top‑20 rankings with Python, C and Java gains, and dives into PHP 8.1’s new features—including enums, read‑only properties, async support, serverless frameworks, and a thriving ecosystem.

21CTO
21CTO
21CTO
What’s New in PHP 8.1? Enums, Read‑only Properties, Async & Serverless Insights

Starting May 1, the Alexa web‑traffic ranking engine will be discontinued, prompting TIOBE to adopt Similarweb; this caused a modest shift in language rankings, with Python, C and Java each gaining over 1%.

PHP, once the dominant web language, continues to evolve. The February TIOBE Top‑20 list shows Python, C and Java rising, while PHP re‑entered the top ten at position 8 and Objective‑C climbed from 24 to 18.

PHP 8.1 introduces several noteworthy language enhancements.

Enums

enum Status {
    case draft;
    case published;
    case archived;

    public function color(): string {
        return match($this) {
            Status::draft => 'grey',
            Status::published => 'green',
            Status::archived => 'red',
        };
    }
}

New in Constructor Default Values

class PostStateMachine {
    public function __construct(
        private State $state = new Draft(),
    ) {}
}

Read‑only Properties

class CCData {
    public function __construct(
        public readonly string $title,
        public readonly PostState $state,
        public readonly DateTimeImmutable $publishedAt,
    ) {}
}

These features, combined with PHP 8.0’s promote, enable clean, elegant data‑class definitions.

Static Analysis Improvements

Static analysis in PHP is advancing: frameworks like Laravel increasingly adopt static typing; PhpStorm now supports generics; and tools such as PhpStan and Psalm continue to mature.

Async PHP

The async community has produced Revolt PHP, an event‑loop implementation from Amp and ReactPHP that aims for fiber‑compatible performance.

Although async PHP remains niche, its ecosystem is growing and embracing modern PHP practices.

Serverless PHP

Serverless computing is a modern development direction, and PHP is keeping pace. The Bref framework, created by Matthieu Napoli, simplifies building serverless PHP functions on platforms like AWS Lambda.

Ecosystem

The PHP ecosystem thrives, centered on Packagist/Composer, which now hosts over three million packages and surpassed 500 billion installations.

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.

ServerlessPHPAsyncEnums8.1Read‑only Properties
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.