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 InformationRelated ArticlesPHP - Essential But Underappreciated PHP 8.0 Adds Metadata To Classes PHP 7.4 Gets Foreign Function Interface PHP 7.2 With Built-in Libsodium PHP Variables and Expressions for Complete Beginners Object-oriented HTML Generation In PHP 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.
Comments
or email your comment to: comments@i-programmer.info |