Skip to content

Fatal error: jddayofweek() undefined when ext-calendar not loaded #228

@parhumm

Description

@parhumm

Source: Support #14684

Summary

Calling jddayofweek() in src/Helpers/DataBuckets.php:118 causes a fatal E_ERROR on PHP installations that lack the optional calendar extension (ext-calendar). This crashes the entire stats dashboard when weekly chart granularity is used.

Affected environments: Synology NAS (DSM), Alpine-based containers, and any PHP build without ext-calendar.

Error

Uncaught Error: Call to undefined function SlimStat\Helpers\jddayofweek()
in src/Helpers/DataBuckets.php:118

Root Cause

jddayofweek() belongs to PHP's optional calendar extension. The code calls it unconditionally at line 118 of DataBuckets.php inside initSeqWeek() without checking whether the extension is loaded. When absent, PHP throws a fatal error.

Causal chain:

  1. User views stats dashboard → Chart.phpprocessResults()
  2. new DataBuckets(...) with WEEK granularity → initBuckets()initSeqWeek()
  3. initSeqWeek() calls jddayofweek($startOfWeek - 1, 1) at line 118
  4. ext-calendar not loaded → fatal error → page crash / 404

Suggested Fix

Replace jddayofweek() with a pure-PHP day-name lookup array:

// Before (line 118):
$start->modify('next ' . jddayofweek($startOfWeek - 1, 1));

// After:
$dayNames = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
$dayName  = $dayNames[$startOfWeek % 7] ?? 'Monday';
$start->modify('next ' . $dayName);

This eliminates the ext-calendar dependency entirely.

Reproduction

  1. Use PHP 8.x without ext-calendar enabled
  2. Install WP Slimstat
  3. Navigate to WP Admin → Slimstat → any dashboard with weekly chart view
  4. Expected: Charts render
  5. Actual: Fatal error crashes the page

Code References

File Line Description
src/Helpers/DataBuckets.php 118 jddayofweek() call — fault location
src/Helpers/DataBuckets.php 103-136 initSeqWeek() method
src/Modules/Chart.php 525 DataBuckets construction with WEEK granularity

Severity

Critical — Completely blocks dashboard access on affected environments. No workaround except enabling ext-calendar in php.ini.


Validated via qa-issue-validate skill (jaan.to plugin)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions