[wp-trac] [WordPress Trac] #40953: Empty values are handled inconsistently between wpdb->get_results() and wpdb->get_col()

WordPress Trac noreply at wordpress.org
Fri Jan 17 14:53:06 UTC 2025


#40953: Empty values are handled inconsistently between wpdb->get_results() and
wpdb->get_col()
--------------------------+------------------------------
 Reporter:  DrewAPicture  |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Database      |     Version:  0.71
 Severity:  normal        |  Resolution:
 Keywords:  dev-feedback  |     Focuses:  performance
--------------------------+------------------------------

Comment (by siliconforks):

 If this is not going to be fixed, shouldn't this odd behavior of `get_col`
 (and `get_var`) at least be explicitly documented?

 The [https://github.com/WordPress/wordpress-
 develop/blob/5e74d3416f6ca7f204ab772cd0b836923bf1ad41/src/wp-includes
 /class-wpdb.php#L3084-L3096 phpdoc comment] for `get_col` does not seem to
 mention this at all.

 The [https://github.com/WordPress/wordpress-
 develop/blob/5e74d3416f6ca7f204ab772cd0b836923bf1ad41/src/wp-includes
 /class-wpdb.php#L3004-L3018 phpdoc comment] for `get_var` describes the
 return value: "Database query result (as string), or null on failure."  I
 suppose you could argue that it means that a column containing the empty
 string is considered a "failure", but that is not at all obvious to me; I
 would assume that "failure" simply means not finding a row in the
 database.

 The documentation at
 https://developer.wordpress.org/reference/classes/wpdb/ also does not seem
 to document this behavior anywhere.

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


More information about the wp-trac mailing list