[wp-trac] [WordPress Trac] #57923: Deprecated notice fired by wp_set_object_terms() with PHP 8.1
WordPress Trac
noreply at wordpress.org
Tue Mar 14 20:59:09 UTC 2023
#57923: Deprecated notice fired by wp_set_object_terms() with PHP 8.1
-------------------------------------------+---------------------
Reporter: Chouby | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.3
Component: Taxonomy | Version:
Severity: normal | Resolution:
Keywords: php81 needs-patch 2nd-opinion | Focuses:
-------------------------------------------+---------------------
Changes (by SergeyBiryukov):
* keywords: php81 needs-patch => php81 needs-patch 2nd-opinion
Comment:
Hi there, thanks for the ticket!
Replying to [ticket:57923 Chouby]:
> It is [https://github.com/Yoast/duplicate-post/pull/293 common practice]
to pass `null` as second parameter of `wp_set_object_terms()` to remove
all terms.
Hmm, the `$terms` parameter is documented as `string|int|array` though, so
as you've already noted, it seems like passing an empty array would be the
correct way to remove all terms, and passing `null` is incorrect.
I think the notice is expected here, putting this guard in place to avoid
a PHP notice when it's `null` is really just papering over the problem
instead of fixing the root cause.
We could consider a `_doing_it_wrong()` notice here if `$terms` is not of
the three supported types, however, as previously noted in
comment:3:ticket:57580, ideally we should have a more structural plan on
whether and how to validate the type of received parameters in core
functions.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57923#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list