[wp-trac] [WordPress Trac] #48027: WP_Comment fields (e.g. user_id) have wrong types

WordPress Trac noreply at wordpress.org
Thu Sep 12 09:37:44 UTC 2019


#48027: WP_Comment fields (e.g. user_id) have wrong types
--------------------------+-----------------------------
 Reporter:  cneumann      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.2.3
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 WP_Comment objects retrieved e.g. with get_comment have wrong types for
 some member variables, e.g. user_id.

 Example:

 {{{#!php
 class TestInsertBug extends \WP_UnitTestCase {
         public function test_insert() {
                 $comment_id = wp_insert_comment( [
                         'user_id' => 1,
                 ] );
                 $comment = get_comment( $comment_id );
                 // will fail because $comment->user_id is a string
                 $this->assertSame( $comment->user_id, 1 );
         }
 }
 }}}

 The constructor of WP_Comment just applies the data to the variables,
 without setting/fixing the types (as e.g. WP_User does for the ID).

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


More information about the wp-trac mailing list