[wp-trac] [WordPress Trac] #42469: WP_Query found_posts inconsistent data type.

WordPress Trac noreply at wordpress.org
Thu Nov 9 18:16:10 UTC 2017


#42469: WP_Query found_posts inconsistent data type.
-------------------------------------------------+-------------------------
 Reporter:  PressLabs                            |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Query                                |  Review
 Severity:  normal                               |     Version:  trunk
 Keywords:  dev-feedback has-unit-tests has-     |  Resolution:
  patch                                          |     Focuses:
-------------------------------------------------+-------------------------
Changes (by birgire):

 * keywords:   => dev-feedback has-unit-tests has-patch


Comment:

 I added a type test in [attachment:42469.2.diff] and removed some extra
 tabs.

 There are some cases in core with {{{(int) apply_filters( ... );}}} so I
 don't think that's a problem with that structure. It sounds logical to
 convert the output from the {{{found_posts}}} filter to integer as well,
 as the definition of the {{{found_posts}}} property says it's of type
 {{{int}}}:

 {{{
 /**
  * The amount of found posts for the current query.
  *
  * If limit clause was not used, equals $post_count.
  *
  * @since 2.1.0
  * @var int
  */
 public $found_posts = 0;

 }}}

 I added the {{{int}}} cast on the {{{found_posts}}} filter in
 [attachment:42469.3.diff], with an extra test.

 But the general concern is if anyone out there is assuming that
 {{{found_posts}}} is a string, for example:

 {{{
 if( '1' === $query->found_posts ) {
    // ...
 }
 }}}

 So I tagged the ticket with {{{dev-feedback}}}.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42469#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list