[wp-trac] [WordPress Trac] #33929: Wrong data type for several variables holding a wpdb query result
WordPress Trac
noreply at wordpress.org
Sat Sep 19 19:38:37 UTC 2015
#33929: Wrong data type for several variables holding a wpdb query result
--------------------------+-----------------------------
Reporter: tfrommen | Owner: boonebgorges
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Future Release
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+-----------------------------
Changes (by boonebgorges):
* milestone: 4.4 => Future Release
Comment:
tfrommen - Thanks for the patch. Some of these changes look more dangerous
than others. For example, `count_user_posts()` will currently return `'0'`
when zero records are found and `null` when there's an error. It's not too
hard to imagine someone doing a strict check on the return value in order
to test whether an error occurred. So this is a case where the logic
should probably be something like:
{{{
$count = $wpdb->get_var( ... );
if ( ! is_null( $count ) ) {
$count = intval( $count );
}
}}}
Even this has the potential to break a plugin that checks `if ( `'0'` ===
count_user_posts( ... ) )`, which again, is not that unreasonable given
the fact that `null` is semantically different in this case.
I'm not opposed to making these kinds of changes in general, but I'm only
comfortable handling them individually, with some thought given to the
possibility of breakage in each case. In some cases, this might involve
searching the plugin repo etc for potentially problematic use cases.
Ideally, we'd also have unit tests for any change :-D
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33929#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list