[wp-trac] [WordPress Trac] #39926: wp_get_object_terms should return WP_Error on wrong fields argument or use a sane default
WordPress Trac
noreply at wordpress.org
Fri Feb 24 04:30:12 UTC 2017
#39926: wp_get_object_terms should return WP_Error on wrong fields argument or use
a sane default
------------------------------------+------------------------------
Reporter: BjornW | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses:
------------------------------------+------------------------------
Comment (by dd32):
> I see the appeal of not duplicating lines of code, however mixing
explicit valid field values with a default 'catch all' does not seem right
to me. The 'default' in the switch is now explicitly used as a catch all,
as you'd expect it to do. That's why I opted for adding a default to the
switch instead of combining it. What do you think about this reasoning?
I still disagree that a duplicated block is the correct way there, perhaps
a more elegant way would be:
{{{
switch( field ) {
default:
// default to 'all'
field = 'all';
// explicit fall through
case 'all':
// ....
}
}}}
duplicating the branch doesn't help future maintainers who change the
`all` branch and miss the default - nor does it convey to the reader that
it's actually the `all` case that it's defaulting to.
Although I suggested that it should maybe update `$args['fields']` I don't
necessarily believe it should - in some cases it may be needed, I don't
know if this is one of those places (I haven't looked close enough)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39926#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list