[wp-trac] [WordPress Trac] #61936: wp_get_object_terms: Unexpected return type (PHP 7.4)/fatal error (PHP 8.0+) when requesting a count
WordPress Trac
noreply at wordpress.org
Sat Aug 31 20:03:43 UTC 2024
#61936: wp_get_object_terms: Unexpected return type (PHP 7.4)/fatal error (PHP
8.0+) when requesting a count
----------------------------+-----------------------------
Reporter: marian1 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: Taxonomy | Version: 2.3
Severity: normal | Resolution:
Keywords: has-unit-tests | Focuses:
----------------------------+-----------------------------
Changes (by marian1):
* keywords: has-patch has-unit-tests => has-unit-tests
Comment:
This is a first step. However, while examining this issue, I found that
this entire section seems incorrect:
{{{#!php
/*
* When one or more queried taxonomies are registered with an 'args'
array,
* those parameters override the `$args` passed to this function.
*/
$terms = array();
if ( count( $taxonomies ) > 1 ) {
foreach ( $taxonomies as $index => $taxonomy ) {
$t = get_taxonomy( $taxonomy );
if ( isset( $t->args ) && is_array( $t->args ) && array_merge(
$args, $t->args ) != $args ) {
unset( $taxonomies[ $index ] );
$terms = array_merge( $terms, wp_get_object_terms(
$object_ids, $taxonomy, array_merge( $args, $t->args ) ) );
}
}
} else {
$t = get_taxonomy( $taxonomies[0] );
if ( isset( $t->args ) && is_array( $t->args ) ) {
$args = array_merge( $args, $t->args );
}
}
}}}
The `$args` that the taxonomies are registered with are located in
`$t->args['args']`, not `$t->args`. Therefore, the condition `array_merge(
$args, $t->args ) != $args )` is always true, but the incorrect array is
merged. The statement "those parameters override the `$args` passed to
this function" will never occur, except for `'hierarchical'`, which is
part of both arrays. However, I am unsure whether this overriding should
occur at all. If the `array_merge` worked as intended, each taxonomy could
have a different `'fields'` value, resulting in a relatively unpredictable
return type.
While the function now returns the expected count when requesting a count,
the actual value is still incorrect when more than one `object_id` is
associated with a term due to double counting. However, I wanted to
discuss this new issue first before continuing.
It's also necessary to review the other functions that call
`wp_get_object_terms()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61936#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list