Make WordPress Core

Opened 6 months ago

Closed 6 months ago

#59129 closed enhancement (duplicate)

Support PHP 8.1's first class calling syntax in _wp_filter_build_unique_id()

Reported by: jkfoiztmcjeikfp's profile jkfoiztmcjeikfp Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords:
Focuses: php-compatibility Cc:

Description

PHP 8.1 introduced a first class calling syntax to pass around methods and functions: https://www.php.net/manual/en/functions.first_class_callable_syntax.php

As it says in the documentation:

CallableExpr(...) syntax is used to create a Closure object from callable.

This causes _wp_filter_build_unique_id() to issue a new id, everytime the first class calling syntax is being used. Each object is correctly identified as a different closure, even though they all execute the same function and are syntactically intended to refer to an identical thing.

This _wp_filter_build_unique_id() behaving this way, causes remove_action() and remove_filter() to not remove remove actions and filters, when called with first class calling syntax.

It also causes filters and actions being added twice by add_action() and add_filter(), when code previously relied on their internal behaviour to not add duplicates.

I would argue that PHP did the community a disservice here. They introduced a standard and preferred way to pass functions and methods around, which causes problems due to them not having the same identity.

Nevertheless they did introduce this as a standard, so WordPress should probably support it.

I would be happy to contribute a solution, where _wp_filter_build_unique_id() checks for first class callables and handles these closures differently than normal ones. Here it could generate the closures syntactical identity, which is what the user cares about, instead of its implementational.

Change History (1)

#1 @swissspidy
6 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #59126.

Note: See TracTickets for help on using tickets.