[wp-trac] [WordPress Trac] #54149: Audit `get_comment()` response checks.

WordPress Trac noreply at wordpress.org
Tue Sep 21 02:38:46 UTC 2021


#54149: Audit `get_comment()` response checks.
----------------------------+-------------------------------
 Reporter:  costdev         |       Owner:  (none)
     Type:  task (blessed)  |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Comments        |     Version:  trunk
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:  coding-standards
----------------------------+-------------------------------

Comment (by costdev):

 Replying to [comment:4 jrf]:
 > Replying to [ticket:54149 costdev]:
 > > @hellofromtonya suggested two alternative checks on the response:
 > >
 > > {{{#!php
 > > <?php
 > > if ( ! $comment instanceof WP_Comment ) {...
 > >
 > > if ( null === $comment ) {...
 > > }}}
 >
 > When validating data and given the choice between checking ''what you
 want'' and checking ''what you don't want'', it's best practice to always
 use the most specific check (which still doesn't break BC), which in this
 case means that (variations of) `if ( $comment instanceof WP_Comment ) {}`
 should be the preferred check.

 Thanks!

 As none of the calls to `get_comment()` make use of a direct check like
 `if ( $comment instanceof WP_Comment ) {}`, it looks like all of the above
 mentioned files will be changed.

 Is there a preference about how to go about submitting changes for this?
 - Should it be in one PR?
 - Separate .diff/.patch for each file or call?
 - Other?

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


More information about the wp-trac mailing list