Make WordPress Core

Changeset 65335


Ignore:
Timestamp:
11/07/2026 11:18:43 PM (8 hours ago)
Author:
SergeyBiryukov
Message:

Tests: Align _test_filter_build_unique_id with _wp_filter_build_unique_id().

Includes:

  • Returning null if the function ID for usage as array key could not be determined.
  • Updating comments for accuracy.

Follow-up to r62408, r63334, r65314.

See #65819.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/functions.php

    r65314 r65335  
    8282 * @param int                   $priority  Unused. The order in which the functions
    8383 *                                         associated with a particular action are executed.
    84  * @return string Unique function ID for usage as array key.
     84 * @return string|null Unique function ID for usage as array key, or null if it couldn't be determined.
    8585 */
    8686function _test_filter_build_unique_id( $hook_name, $callback, $priority ) {
    … …  
    9090
    9191        if ( is_object( $callback ) ) {
    92                 // Closures are currently implemented as objects.
     92                /*
     93                 * The prefix keeps the ID from being the decimal representation of an integer. PHP casts such a
     94                 * string to int when it is used as an array key, which would change the type of the keys in
     95                 * WP_Hook::$callbacks and break consumers that pass them to string functions.
     96                 */
    9397                return 'spl_object_id:' . spl_object_id( $callback );
    9498        }
    9599
    96         $callback = (array) $callback;
     100        if ( ! isset( $callback[1] ) || ! is_string( $callback[1] ) ) {
     101                return null;
     102        }
    97103
    98104        if ( is_object( $callback[0] ) ) {
    … …  
    103109                return $callback[0] . '::' . $callback[1];
    104110        }
     111
     112        return null;
    105113}
    106114
Note: See TracChangeset for help on using the changeset viewer.