Fix null activity objects causing PHP warnings#4919
Fix null activity objects causing PHP warnings#4919GaryJones wants to merge 2 commits intobuddyboss:releasefrom
Conversation
When an activity ID exists in query results but the corresponding row has been deleted from the database, wp_cache_get() returns false. get_activity_data() unconditionally adds this falsy value to the $activities array, causing PHP warnings when downstream code accesses properties on null entries (->id, ->mptt_right, ->component). Only add the activity to the return array when it is a valid object. Add a defensive is_object() check in bp_friends_prefetch_activity_object_data() as well.
62f6c63 to
e031f46
Compare
|
@claude Review the PR |
|
Claude finished @chetansatasiya's task in 1m 39s —— View job PR Review: Fix null activity objects causing PHP warnings
Summary: This PR fixes three PHP warnings triggered when activity rows are deleted from the database but their IDs remain referenced (e.g. in a query result). The root cause is in
|
| Area | Assessment |
|---|---|
| Correctness | ✅ Fixes all three documented warnings |
| Coding standards | ✅ WordPress tabs, ! empty() / is_object(), space after if |
| Backward compatibility | ✅ Activities that exist continue to work; only missing/stale entries are skipped |
| Edge cases | ✅ false, null, 0, "" all pass empty() and are excluded |
| Tests | wp_cache_get returning false for a subset of IDs would lock this in and prevent regressions. |
| Negative caching | 🔍 If a caller explicitly sets a cache entry to false (negative cache) for a known-missing ID, the fix correctly excludes it. This is the desired behaviour. |
Verdict
The fix is correct, minimal, and safe to merge. The only gap worth noting is the absence of a unit test to prevent this from regressing. If the project's test suite can exercise get_activity_data() with a stale cache entry, a test would be a worthwhile follow-up.
Problem
When activity rows are deleted from the database but their IDs are still
referenced (e.g. in cached query results),
BP_Activity_Activity::get_activity_data()adds
falseentries to the$activitiesarray. This happens becausewp_cache_get()returnsfalsefor missing cache keys, and the resultis unconditionally appended to the array regardless of validity.
Downstream code then iterates over these null entries and attempts
property access, producing three PHP warnings:
Fix
get_activity_data()— wrap the$activities[] = $activityassignment with
if ( ! empty( $activity ) )so that only validobjects are added to the return array. This is the root cause fix
and prevents all three warnings.
bp_friends_prefetch_activity_object_data()— add a defensiveis_object()check to skip non-object entries, protecting againstany code path that might pass invalid data into this function.
Testing
bp_activitytable without clearingthe object cache or any referencing queries
appear