Make WordPress Core


Ignore:
Timestamp:
01/24/2018 09:43:17 PM (8 years ago)
Author:
jorbin
Message:

Query: Fix warning on counting non countable

Merges [42581], [42585], and [42594] to the 4.9 branch.

Adds tests to continue the behavior for both null and strings. Skip the tests on PHP 5.2 as they require ReflectionMethod.

See https://wiki.php.net/rfc/counting_non_countables for information on the PHP change.

Fixes #42860.
Props dd32 for test skipping and janak007 and ayeshrajans for initial patches.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/class-wp-query.php

    r41688 r42597  
    30333033            $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) );
    30343034        } else {
    3035             $this->found_posts = count( $this->posts );
     3035            if ( is_array( $this->posts ) ) {
     3036                $this->found_posts = count( $this->posts );
     3037            } else {
     3038                if ( null === $this->posts ) { 
     3039                    $this->found_posts = 0;
     3040                } else {
     3041                    $this->found_posts = 1;
     3042                }
     3043            }
    30363044        }
    30373045
Note: See TracChangeset for help on using the changeset viewer.