[wp-trac] [WordPress Trac] #50767: Coding Standards fixes for WP 5.6

WordPress Trac noreply at wordpress.org
Sun Oct 18 18:13:14 UTC 2020


#50767: Coding Standards fixes for WP 5.6
--------------------------------------+-------------------------------
 Reporter:  SergeyBiryukov            |       Owner:  (none)
     Type:  task (blessed)            |      Status:  new
 Priority:  normal                    |   Milestone:  5.6
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  coding-standards
--------------------------------------+-------------------------------

Comment (by jrf):

 > Should we bring some consistency to the other instances too?

 That would be a good idea. The current patch was very focused on some
 problems identified by a static analysis tool.

 > Since $wpdb->get_row() returns an object by default, unless requested
 otherwise, I think a simple `if ( $signup )` or `if ( is_object( $signup )
 )` check would be enough here.

 Both would still be an unsafe comparison, though the second one less so
 than the first.

 The patch was about unsafe assumptions and doing an `if ( $signup )` is
 still an unsafe assumption as `get_row()` can also return an array
 depending on the parameters passed and in that case, the comparison will
 still pass, but the code in the body of the condition will fail.

 The safe comparison is `instanceof stdClass`, as that is actually testing
 for what the rest of the code is expecting.

 That also prevents problems in the future if `get_row()`, for instance,
 would start returning a `WP_Error` object on failure instead of `null`,
 though it doesn't allow for `get_row()` to return a row object of another
 type, like `WPDB_Row` in the future.

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


More information about the wp-trac mailing list