Make WordPress Core

Opened 9 years ago

Closed 6 years ago

Last modified 6 years ago

#34565 closed defect (bug) (fixed)

Warning after change theme

Reported by: sebastianpisula's profile sebastian.pisula Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.1 Priority: normal
Severity: normal Version: 3.4
Component: Themes Keywords: has-patch 2nd-opinion
Focuses: Cc:



uasort(): Array was modified by the user comparison function


WordPress version 4.3.1

PHP Version: 5.5.9

Attachments (2)

34565.patch (743 bytes) - added by sebastian.pisula 9 years ago.
34565.2.patch (975 bytes) - added by bobbingwide 9 years ago.
Pre-translate before sorting names when locale not english

Download all attachments as: .zip

Change History (13)

#1 @sebastian.pisula
9 years ago

  • Component changed from General to Themes
  • Keywords has-patch added

#2 @johnbillion
9 years ago

  • Keywords 2nd-opinion added
  • Version changed from 4.3.1 to 3.4

As mentioned in the SO thread, neither _name_sort() nor _name_sort_i18n() modify the input array, but they still apparently trigger this warning due to PHP bug 50688. However, either of these methods appear to use var_dump(), print_r(), debug_backtrace(), error_log(), or exceptions, although there might be one buried in there somewhere.

Error suppression is nasty but it might be the easiest solution.

#3 @bobbingwide
9 years ago

Just like to point out that when the locale is not 'en_' with 83 themes, WP_Theme::_name_sort_i18n is called 890 times. Time 0.047 secs.
It would be more efficient to pre-translate the Name field before calling uasort()

foreach ( $themes as $key => $theme ) {
  $theme->display( "Name", false, true );

and replace the business logic in _name_sort_i18n() with

return strnatcasecmp( $a->name_translated, $b->name_translated );

The sort function is still called the same number of times, but it is slightly quicker.

BTW. I was unable to get the Warning message without resorting to using print_r() in the sort function.
Would like to know more details how to produce the message. Using PHP 5.5.18

#4 @bobbingwide
9 years ago

I was able to reproduce the problem by switching to a theme that produced deprecated messages.

Notice: The called constructor method for WP_Widget is deprecated since version 4.3.0! Use
instead. in C:\apache\htdocs\wordpress\wp-includes\functions.php on line 3457

Another way to achieve it was to implement hooks to the filters invoked during the display(): 'load_textdomain', 'gettext' and use the functions in these hooks. In my case I simply traced the hook invocation.

The alternative solution, pre-translate, avoids these problems.

9 years ago

Pre-translate before sorting names when locale not english

#5 @sebastian.pisula
8 years ago

WordPress 4.4.1. error still exists

#6 @bobbingwide
8 years ago

@sebastian.pisula can you furnish more details of how you get the error. Have you tried applying the 34565.2.patch ?

#7 @sebastian.pisula
8 years ago

Details from Query Monitor:

Warning: uasort(): Array was modified by the user comparison function

Location: wp-includes/class-wp-theme.php:1322

Call Stack:


WordPress version: 4.5-alpha-36504

Url: http://localhost/wordpress/wp-admin/themes.php

PHP Version 5.5.9

Windows 10 (Windows NT SPISULA 6.2 build 9200 (Windows 8 Home Premium Edition) i586)

Active theme: Divi Child (Child of Divi)

This ticket was mentioned in Slack in #core by sebastian.pisula. View the logs.

8 years ago

#9 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 5.0

#10 @SergeyBiryukov
6 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 42734:

Themes: Pre-translate theme names on Themes screen before sorting the array, to improve performance and avoid a warning in PHP 5.x.

Props bobbingwide, sebastian.pisula.
Fixes #34565.

#11 @johnbillion
6 years ago

  • Milestone changed from 5.0 to 5.1
Note: See TracTickets for help on using tickets.