pr: [Nightly Fix] - Null Safety - Guard Missing Subscription Total in Dashboard Widget#57
Open
jewel-claw wants to merge 1 commit into
Open
Conversation
… Dashboard Widget $subsTotal[0]->recurring_total was accessed unconditionally inside a foreach loop. If the wpf_subscriptions table is empty or the SUM query returns no rows, $subsTotal would be an empty array and accessing index [0] causes a PHP notice or fatal error depending on error reporting level. Also, recurring_total is a SUM aggregate — it returns NULL when there are no matching rows, so intval(null) = 0 was masking the issue silently in some cases but explicit property access on a non-existent stdClass would fail. Fix: extract the recurring total before the loop with a null guard, defaulting to 0 if no subscriptions exist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In
DashboardWidgetModule::showStat(),$subsTotal[0]->recurring_totalwas accessed unconditionally inside aforeachloop.When there are no active subscriptions in
wpf_subscriptions, the aggregateSUM()query returns an empty result set — making$subsTotalan empty array. Accessing$subsTotal[0]triggers anUndefined offset: 0PHP warning/notice, and then accessing->recurring_totalon a non-object would be a fatal error.Fix: Extract the recurring total once before the loop with an explicit empty check, defaulting to
0if no subscriptions exist. This also avoids re-accessing the same array element on every iteration of the loop.