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. 

phplogosq24

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.

phplogosq24

More Information

PHP Website

Related Articles

Is PHP in Trouble?

PHP 8.3 Released

Updated For PHP 8.3

PHP Adds Read-Only Classes

PHP - Essential But Underappreciated

Ten Minutes to PHP

PHP Is Best?

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.

Banner


Data Wrangler Gets Copilot Integration
11/11/2024

Microsoft has announced that Copilot is being integrated into Data Wrangler. The move will give data scientists the ability to use natural language to clean and transform data, and to get help with fi [ ... ]



Amazon Adds AWS Lambda Code Editing Tool
04/11/2024

Amazon has added a new code editing option for AWS Lambda in the AWS console based on the Code-OSS, Visual Studio Code Open Source code editor.


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Tuesday, 26 November 2024 )