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.


JConference January 2024 Sessions Now Online

The talks presented at the 4th JChampions Conference which took place between Jan 25 to Jan 30, are now available for free on YouTube. Topics ranged from Code and Tech to Career Advice.

IDX Gets Android Emulator & iOS Simulator

Google has updated Project IDX, its browser-based development tool, adding an iOS Simulator and Android Emulator to the browser so developers can preview apps directly in IDX. The updated release also [ ... ]

More News

raspberry pi books



or email your comment to: