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


Rust Foundation Update On Goals
03/02/2025

Over the last six months, the Rust project has been working towards implementing 26 project goals, with 3 of them designated as Flagship Goals. The team has now provided an end-of-year update on progr [ ... ]



European Robotics Hackathon 2025 Open For Entries
17/01/2025

ENRICH 2025, the European Robotics Hackathon, is open now for team entries. To be held at the Zwentendorf Nuclear Power Plant in Austria, the aim is to develop robots that can carry out tasks in a nuc [ ... ]


More News

espbook

 

Comments




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

Last Updated ( Tuesday, 26 November 2024 )