PHP Adds Read-Only Classes
Written by Kay Ewbank   
Wednesday, 28 December 2022

PHP 8.2 has been released with improvements including read-only classes, new standalone types,  deprecated dynamic properties and a new random extension.

PHP began life 25 years ago as a simple scripting language designed to build web pages but has developed into a general server side web language . It is now used for eight out of ten websites using server-side code. 


The new support for read-only classes extends the support for read-only properties that was added in PHP 8.1. The need for read-only classes arose because the read-only properties still didn't make it easy to declare (quasi-)immutable classes, especially if they contain many properties.

The second improvement is the addition of support for Disjunctive Normal Form (DNF) types to make it possible to mix union and intersection types. DNF is a standard way of organizing boolean expressions to structure a boolean expression into an ORed series of ANDs, creating a standard way to write combined union and Intersection types that the parser can handle.

The new support for standalone types extends PHP's existing support for null, false and true. Until now, you could use these as parts of union types but would get a fatal error if you tried to declare them as standalone types. The addition makes such declarations possible. This has been done for type system completeness, and to handle some edge cases when used in union types.

The new random number generator aims to overcome the various problems with earlier generators, specifically their performance, what they can be used for, and how good they have been for secure applications. The new generator is described as more secure and performant.

A final improvement in this release is support for the use of Constants in traits. Traits in PHP give developers the ability to reuse methods from independent classes. Until now, traits only allowed you to define methods and properties, not constants. This has now been extended.

PHP 8.2 is now available for download.


More Information

PHP Website

Related Articles

PHP - Essential But Underappreciated

Ten Minutes to PHP

PHP Is Best?

PHP 8.0 Adds Metadata To Classes

PHP 7.4 Gets Foreign Function Interface

PHP 7.2 With Built-in Libsodium

What PHP Does

PHP Variables and Expressions for Complete Beginners

Object-oriented HTML Generation In PHP

PHP 5.6 Released

PHP Gets A Formal Specification 


To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.


Runaway Success Of ChatGPT

We already knew that OpenAI's chatbot, ChatGPT, was a phenomenal success. Now we have the numbers to prove it. Meanwhile OpenAI has announced pricing for premium access to the ChatGPT API.

Revealing The Top Skills For 2023

When it comes to the skills that are going to be in demand in the coming year, what can we learn from the 2023 HackerRank Developer Skills Report? It probably comes as little surprise that Data Scienc [ ... ]

More News





or email your comment to: