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

WordPress Trac noreply at wordpress.org
Tue Sep 21 02:28:26 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 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.

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


More information about the wp-trac mailing list