[wp-trac] [WordPress Trac] #59129: Support PHP 8.1's first class calling syntax in _wp_filter_build_unique_id()

WordPress Trac noreply at wordpress.org
Thu Aug 17 09:50:44 UTC 2023


#59129: Support PHP 8.1's first class calling syntax in
_wp_filter_build_unique_id()
-------------------------------+-----------------------------
 Reporter:  jkfoiztmcjeikfp    |      Owner:  (none)
     Type:  enhancement        |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Plugins            |    Version:
 Severity:  normal             |   Keywords:
  Focuses:  php-compatibility  |
-------------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59129>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list