Opened 3 years ago
Last modified 3 weeks ago
#59785 new defect (bug)
Fatal error: Attempt to assign property “object_id” on bool in class-wp-term-query.php
| Reported by: | Faar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Taxonomy | Version: | 6.3.3 |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The populate_terms() function in this class still throws a PHP fatal error on the get_term() query. Why?
In special circumstances, get_term() returns NULL and the variable $term is not checked to see if it is still an object or already boolean.
$term = NULL and this leads to a fatal PHP error and the page loading is aborted because $term->object_id does not work with NULL.
NULL->object_id
More to read here:
https://wordpress.org/support/topic/fatal-error-attempt-to-assign-property-object_id-on-bool/
Attachments (1)
Change History (8)
#2
@
2 years ago
I can also confirm that it fixed the issue for us as well (in 6.6.2). What do we need to do to get this into core ASAP?
This ticket was mentioned in Slack in #core by robinmartijn. View the logs.
2 years ago
#4
@
17 months ago
Is there any indication when this fix is going to be merged?
It seems its not had any activity for a while.
This ticket was mentioned in PR #14843 on WordPress/wordpress-develop by @nofearinc.
3 weeks ago
#5
- Keywords has-patch has-unit-tests added
In WP_Term_Query::populate_terms(), rows that carry an object_id or count are assigned to the result of get_term() before it is checked. When the term no longer resolves, for example because a persistent cache still lists a deleted term or a get_term filter returns null, this is a fatal error: Attempt to assign property "object_id" on null.
The function already discards anything that is not a WP_Term a few lines later, so this skips such terms before the assignments, the same guard [60661] added for child terms in #63877. One guard covers both the object_id and the count assignment.
Testing
vendor/bin/phpunit --filter test_unresolvable_term_with_object_id_should_be_discardedfails without the patch withAttempt to assign property "object_id" on nulland passes with it.vendor/bin/phpunit --group taxonomy(1122 tests) passes.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: reproducing the fatal in trunk, drafting the fix and test, and running them. I reviewed every line.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code
#6
@
3 weeks ago
Still reproducible in trunk. https://github.com/WordPress/wordpress-develop/pull/14843 skips terms that no longer resolve before object_id and count are assigned, the same guard [60661] added for child terms in #63877, and adds a unit test. The change in comment:1 only guards object_id, so the count assignment right after it could still fail. Thanks @Faar and @gliautard for the earlier fixes.
AI assistance: Claude Code (Claude Opus 5.5) for reproducing the fatal and drafting the fix and test; reviewed and tested by me.
#7
@
3 weeks ago
Thanks @nofearinc
I hit this on a multisite network with about 30 blogs. A language plugin had not migrated its old tables correctly, and some columns (with data) were missing but i ddin'tknow which one. After blog owners changed their language settings false through the normal admin screen years before, get_term() returned null inside WP_Term_Query::populate_terms().
The code assigns $term->object_id and $term->count without checking that $term is a WP_Term, which causes a fatal error on PHP 8. Note that a guard for object_id alone is not enough, since the count assignment fails the same way. Because this fatal-error i lost my job for the multisite, it isn't WordPress anymore.
This solved the Error:
Asking, if is object $term.