Fix exception "Deprecated function: usort(): Returning bool from comparison function is deprecated" being thrown on PHP 8.2.

Created on 29 August 2024, 4 months ago

Problem/Motivation

This module is causing this message to be thrown when running on D10 with PHP 8.2:

Deprecated function: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in Drupal\preprocess\PreprocessPluginManager->sortPreprocessors() (line 174 of modules/contrib/preprocess/src/PreprocessPluginManager.php).

Steps to reproduce

Install this module on Drupal 10 and make sure it is running on PHP version 8.2 (not 8.1, as 8.1 accepts the output of usort to be a boolean).

Proposed resolution

Just cast the output of the expression on line 174 as an integer, rather than a boolean, as usort is expecting an integer as the result of the expression: https://www.php.net/manual/en/function.usort.php: "The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second."

Remaining tasks

--

User interface changes

A fix to this error has no UI effect.

API changes

--

Data model changes

--

🐛 Bug report
Status

Closed: works as designed

Version

2.1

Component

Code

Created by

🇧🇷Brazil mabho Rio de Janeiro, RJ

Live updates comments and jobs are added and updated live.
  • PHP 8.2

    The issue particularly affects sites running on PHP version 8.2.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024