Menü schliessen
Created: February 27th 2026
Last updated: February 27th 2026
Categories: IT Development,  Php
Author: Ian Walser

PHP 8 Features You're Probably Underusing: Fibers, Enums & Readonly Properties Explained

Introduction

PHP 8.x has been a game-changer for the language — but many developers, especially those just starting out, continue writing PHP the same way it was written in the PHP 5 or 7 era. Here are three powerful modern PHP features you should start using today.


1. Enums (PHP 8.1)

Enums let you define a type restricted to a fixed set of values. Before Enums, developers used class constants or plain strings to represent things like statuses — which was error-prone and hard to enforce. Backed Enums can carry a string or integer value, making them perfect for database storage or API responses.

<?php

enum Status: string {
    case Draft     = 'draft';
    case Published = 'published';
    case Archived  = 'archived';
}

function publishPost(int $postId, Status $status): void {
    echo "Setting post #{$postId} to: " . $status->value;
}

publishPost(42, Status::Published); // Setting post #42 to: published
// publishPost(42, 'published');    // TypeError — invalid value!

2. Readonly Properties (PHP 8.1) & Readonly Classes (PHP 8.2)

Readonly properties can only be assigned once — in the constructor. After that, any attempt to modify them throws an error. This enforces immutability and eliminates a whole class of bugs where an object gets accidentally mutated somewhere in your codebase. In PHP 8.2, you can mark an entire class as readonly instead of decorating each property individually.

<?php

readonly class User {
    public function __construct(
        public int    $id,
        public string $email,
        public string $name,
    ) {}
}

$user = new User(id: 1, email: 'jane@example.com', name: 'Jane Doe');

echo $user->name;   // Jane Doe
$user->name = 'X'; // Error: Cannot modify readonly property

3. Fibers (PHP 8.1)

Fibers are PHP's approach to cooperative multitasking. A Fiber is a pausable unit of execution — you can suspend it mid-run, do something else, and resume it later, all within a single PHP process. You likely won't use Fibers directly in everyday Laravel or Symfony work, but they're the low-level primitive powering async PHP libraries like Amp and ReactPHP. Understanding them makes you a much stronger developer.

<?php

$fiber = new Fiber(function(): void {
    echo "Fiber started\n";
    $value = Fiber::suspend('paused!');
    echo "Fiber resumed with: {$value}\n";
});

$suspended = $fiber->start();       // "Fiber started"
echo "Main got: {$suspended}\n";    // "Main got: paused!"
$fiber->resume('hello back');       // "Fiber resumed with: hello back"