[wp-trac] [WordPress Trac] #43374: PHP 7.2 Warning: count(): Parameter must be an array or an object that implements Countable in /wp-includes/theme.php on line 356

WordPress Trac noreply at wordpress.org
Wed Feb 21 01:11:19 UTC 2018


#43374: PHP 7.2 Warning: count(): Parameter must be an array or an object that
implements Countable in /wp-includes/theme.php on line 356
------------------------------+-----------------------------
 Reporter:  burlingtonbytes   |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Themes            |    Version:  4.9.4
 Severity:  normal            |   Keywords:
  Focuses:  coding-standards  |
------------------------------+-----------------------------
 After upgrading to PHP 7.2 from 7.0 we observed PHP warnings on every
 pageload. It looks like `get_theme_roots()` runs `count()` on `global
 $wp_theme_directories` without checking the value first.

 '''Proposed solution''': check if `empty($wp_theme_directories)` before
 performing `count()`.

 patched version of get_theme_roots (wp-includes/theme.php line 356 in WP
 4.9.4)
 {{{
 function get_theme_roots() {
         global $wp_theme_directories;

         if ( empty($wp_theme_directories) || count($wp_theme_directories)
 <= 1 )
                 return '/themes';

         $theme_roots = get_site_transient( 'theme_roots' );
         if ( false === $theme_roots ) {
                 search_theme_directories( true ); // Regenerate the
 transient.
                 $theme_roots = get_site_transient( 'theme_roots' );
         }
         return $theme_roots;
 }
 }}}

 We haven't observed this in a clean WordPress install, so we aren't sure
 why `$wp_theme_directories` would be empty, but this patch resolves the
 PHP warning while maintaining the existing, expected PHP <7.2 behavior.

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


More information about the wp-trac mailing list