PHP 8.1 – Read-only class properties

barrier gate
barrier gate

To ensure the class property will never be modified/changed by itself or children or external calls we can now use a readonly prefix to class property declaration like so: public readonly string $propertyName = 'thisValueWillNeverChange;. The only place when we could override the readonly variable is inside the class constructor.

Read morePHP 8.1 – Read-only class properties

PHP 8.1 – Default parameters with “new” keyword

abstract gradients
abstract gradients

Currently we could only assign a default parameter value of nullarray or primitive types in functions and methods. In PHP 8.1 we will be able to provide any custom class as default value for our expected function parameter. This includes defining a class variables inside the parameters as well.

Read morePHP 8.1 – Default parameters with “new” keyword

PHP 8.1 – Asynchronous and lightweight thread execution: Fibers

fibers thread execution in php
fibers thread execution in php
Fibers allow the creation of full-stack, incorruptible functions that can be used to develop cooperative multitasking in PHP. This feature eliminates the distinction between sync and async functions by allowing them to be incorruptible without breaking the entire call stack.

Read morePHP 8.1 – Asynchronous and lightweight thread execution: Fibers