PHP 8.4 Adds Property Hooks |
Written by Kay Ewbank |
Tuesday, 26 November 2024 |
PHP 8.4 is available with improvements including property hooks, asymmetric visibility, and an updated DOM API. PHP began life 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. Property hooks are also known as property accessors in some other languages, and provide a way to intercept and override the read and write behavior of a property. The addition of support for property hooks in PHP means that object properties can now have additional logic associated with their get and set operations. Depending on the usage, that may or may not make the property virtual, with no backing value at all. The next improvement is that object properties may also have their visibility set asymmetrically, with a different scope for reading ( get ) and writing ( set ). Specifically, the set visibility may be specified separately, provided it is not more permissive than the default visibility. The syntax has been heavily influenced by Swift. This release also adds support for lazy objects, objects whose initialization is deferred until they are accessed. Libraries and frameworks can make use of lazy objects to defer fetching data or dependencies required for initialization. A final addition is a new Deprecated attribute that can be used to mark functions, methods, and class constants as deprecated. The behavior of functionality deprecated with this attribute matches the behavior of the existing deprecation mechanism for functionality provided by PHP itself. Two new APIs are included in this release. There's a new DOM API that includes standards-compliant support for parsing HTML5 documents, fixes several long-standing compliance bugs in the behavior of the DOM functionality, and adds several functions to make working with documents more convenient. A new Object API for BCMath has also been added. This enables object-oriented usage and standard mathematical operators when working with arbitrary precision numbers. PHP 8.4 is available for download now. More InformationRelated ArticlesPHP - Essential But Underappreciated PHP 8.0 Adds Metadata To Classes 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 |
Last Updated ( Tuesday, 26 November 2024 ) |