Do not declare compatibility with PHP 9, 10, 11 and beyond right now

Created on 8 June 2023, over 1 year ago
Updated 24 January 2024, 11 months ago

Problem/Motivation

We are currently declaring a compatibility with php: >=8.1. This means we are formally declaring to Composer that our code is fully compatible with PHP 8, but also with PHP 9, and even with PHP 10, 11 and so on. This is not realistic. We cannot promise today that the module in its current form will work on any future PHP version for as long as PHP continues to exist.

PHP has a guarantee of not breaking backwards compatibility within major releases so it is safe to use php: ^8.1. But future versions WILL break backwards compatibility. That is actually the whole point of issuing a new major PHP version. Looking at the current list of approved RFCs, major breakage is already planned. See for example PHP RFC: Undefined Property Error Promotion.

We have a history of the php: >=7 pattern causing problems when we transitioned the Drupal ecosystem from PHP 7 to PHP 8. The pattern was widely used and started causing trouble for modules that had previously unknown PHP 8 compatibility bugs. Modules started issuing new releases compatible with PHP 8. But the problem was that _older_ incompatible versions would still be installed by Composer due to using this permissive version declaration. Composer knows the _entire_ version history of a project. Composer also puts absolute trust in this declaration. It will happily downgrade modules to ancient versions for as long as it finds a PHP version that resolves.

This is especially problematic when new major issues of the modules are released at the same time, which is a very common pattern. Many module maintainers decide to release a new major version which includes support for the new PHP version.

Even Drupal core was hit by this. Drupal 8.9 and 9.0 were not compatible with PHP 8. The first compatible version was Drupal 9.1. But due to the php: >=7.0 declaration these versions were still being installed by Composer. We had to intervene and update this version declaration. See Issue #3156651: Prevent Drupal 8.9 and 9.0 from being installed on PHP 8. Unfortunately we could not go back in time and fix the string for earlier releases. Even up to today, if you are on PHP 8.2 and install Drupal 8 through Composer, it will decide that version 8.8.12 is the latest version that is compatible (since it declares php: >=7.0.8) and will happily install that.

Proposed resolution

  1. Declare compatibility with php ^8.1.
  2. Once a PHP 9 beta is out, we can start testing it. As soon as we have fixed all incompatibilities we can update the version string to php: ^8.1 || ^9
🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇧🇬Bulgaria pfrenssen Sofia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024