There are several new interfaces that can potentially alter how we work with the DOM and DateTime extensions. For the most part, the changes improve the abilities of these two extensions. However, because method signatures have changed in some cases, we may run into a potential code break. Due to this, it’s important to pay close attention to the discussion presented in this section to ensure that existing and future PHP code remains functional.

First, let’s have a look at the new DOM extension interfaces.

Discovering new DOM extension interfaces

The cost of living economic statistic is issued each year by many world governments. It depicts how much it costs an average citizen to live year by year. As web technology matures, a similar principle has been applied—first to HTML and now to DOM. The DOM Living Standard is maintained by the Web Hypertext Application Technology Working Group (WHATWG).

The reason why this information is important to PHP developers is that in PHP 8, the decision was made to move the PHP DOM extension to the DOM Living Standard. Accordingly, starting with PHP 8, a series of incremental and continuous changes will be applied to this extension in accordance with changes to the living standard.

For the most part, the changes are backward compatible. However, since some method signatures change to maintain adherence to the standard, we may experience code breaks. The most significant change to the DOM extension in PHP 8 is the introduction of two new interfaces. Let’s examine these interfaces and then discuss their impact on PHP development.

Examining the new DOMParentNode interface

The first of the two new interfaces is DOMParentNode. The following classes implement this interface in PHP 8:

  • DOMDocument

  • DOMElement

  • DOMDocumentFragment

Here is the interface definition:

Get hands-on with 1200+ tech skills courses.