Make WordPress Core


Ignore:
Timestamp:
07/05/2023 10:44:20 AM (3 years ago)
Author:
SergeyBiryukov
Message:

General: Compare values as strings in WP_List_Util::filter() and ::sort_callback().

This aims to preserve backward compatibility for code relying on type juggling when using the wp_list_filter() function, e.g. comparing a numeric string to an integer.

Follow-up to [55908].

Props azaozz, jeremyfelt, david.binda.
See #57839.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-list-util.php

    r55908 r56137  
    117117                                if ( is_array( $obj ) ) {
    118118                                        // Treat object as an array.
    119                                         if ( array_key_exists( $m_key, $obj ) && ( $m_value === $obj[ $m_key ] ) ) {
     119                                        if ( array_key_exists( $m_key, $obj )
     120                                                && ( (string) $m_value === (string) $obj[ $m_key ] )
     121                                        ) {
    120122                                                $matched++;
    121123                                        }
    122124                                } elseif ( is_object( $obj ) ) {
    123125                                        // Treat object as an object.
    124                                         if ( isset( $obj->{$m_key} ) && ( $m_value === $obj->{$m_key} ) ) {
     126                                        if ( isset( $obj->{$m_key} )
     127                                                && ( (string) $m_value === (string) $obj->{$m_key} )
     128                                        ) {
    125129                                                $matched++;
    126130                                        }
     
    277281                        }
    278282
    279                         if ( $a[ $field ] === $b[ $field ] ) {
     283                        if ( (string) $a[ $field ] === (string) $b[ $field ] ) {
    280284                                continue;
    281285                        }
Note: See TracChangeset for help on using the changeset viewer.