Skip to content

pr: [Nightly Fix] - Null Safety - Guard Missing Subscription Total in Dashboard Widget#57

Open
jewel-claw wants to merge 1 commit into
masterfrom
nightly-fix/guard-null-subscription-total-dashboard
Open

pr: [Nightly Fix] - Null Safety - Guard Missing Subscription Total in Dashboard Widget#57
jewel-claw wants to merge 1 commit into
masterfrom
nightly-fix/guard-null-subscription-total-dashboard

Conversation

@jewel-claw

Copy link
Copy Markdown

Summary

In DashboardWidgetModule::showStat(), $subsTotal[0]->recurring_total was accessed unconditionally inside a foreach loop.

When there are no active subscriptions in wpf_subscriptions, the aggregate SUM() query returns an empty result set — making $subsTotal an empty array. Accessing $subsTotal[0] triggers an Undefined offset: 0 PHP warning/notice, and then accessing ->recurring_total on a non-object would be a fatal error.

Fix: Extract the recurring total once before the loop with an explicit empty check, defaulting to 0 if no subscriptions exist. This also avoids re-accessing the same array element on every iteration of the loop.

… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant