[wp-trac] [WordPress Trac] #25429: `get_the_category_by_ID` triggers PHP notice on non-existent category
WordPress Trac
noreply at wordpress.org
Thu Oct 3 14:39:15 UTC 2013
#25429: `get_the_category_by_ID` triggers PHP notice on non-existent category
------------------------------------+------------------
Reporter: ericmann | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 3.7
Component: Taxonomy | Version: 2.3
Severity: normal | Resolution:
Keywords: has-patch dev-feedback |
------------------------------------+------------------
Comment (by ericmann):
Replying to [comment:3 johnbillion]:
> Should we match `get_tag()` for consistency by returning `null`, or
should we return a `wp_error` as per Sergey's patch?
Took some time to think about this, and I agree that since `get_tag()`
returns `null`, then `get_category()` should do the same. However,
`get_the_category_by_ID()` erring when `get_category()` returns null is
still a problem, so I've moved Sergey's error call higher up the stack.
Some code in production might already be counting on
`get_tag()`/`get_category()` returning null for nonexistent categories.
Anyone doing an `if ( null === get_category( $something ) )` check would
see a lot of huge issues if we suddenly start returning `WP_Error`
instead. But since `get_the_category_by_ID()` will currently break with a
bad category, we should do the `null` check inside there to prevent
explosions.
Patch 25429.3 adds Sergey's docblock edits to `get_category()` and also
adds a `null` check to `get_the_category_by_ID()`. Method returns aren't
changed, but this will fix the PHP notice reported above.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25429#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list