Skip to content

Gate pre-1.3 report shims on Cacti version to stop redeclare on 1.3.0 develop - #289

Merged
TheWitness merged 2 commits into
developfrom
fix/pre13-reports-shim-version-gate
Oct 9, 2026
Merged

TheWitness merged 2 commits into
developfrom
fix/pre13-reports-shim-version-gate

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Problem

On a Cacti 1.3.0 develop build, loading a page/poller that pulls in core's report library fatally errors:

ERROR PHP ERROR: Cannot redeclare reports_log_and_notify()
(previously declared in .../plugins/flowview/includes/functions-pre13.php:49)
in file: .../lib/reports.php on line: 2178

reports_run() / reports_queue() / reports_log_and_notify() became native in Cacti 1.3. The plugin's includes/functions.php gated its pre-1.3 shims (includes/functions-pre13.php) behind !function_exists('reports_run'). But functions.php is included during plugin init before core loads lib/reports.php, so the probe runs while the now-native helpers are still absent, declares the shims, and core then fatally redeclares them when lib/reports.php is finally included. A function_exists() check can't win a load-order race.

Fix

Gate the shims on the Cacti version, which is fixed at bootstrap and independent of include order:

if (
    (function_exists('cacti_version_compare') && defined('CACTI_VERSION'))
        ? cacti_version_compare(CACTI_VERSION, '1.3', '<')
        : !function_exists('reports_run')
) {
    require_once(__DIR__ . '/functions-pre13.php');
}

cacti_version_compare() treats a 1.3.0 develop build (CACTI_VERSION resolves to '1.3.0') as >= 1.3, so the shims are loaded only on genuinely older releases (the plugin still declares compat = 1.2.29). The function_exists() fallback is retained for the one case the Cacti version helpers aren't available — including functions.php outside a full Cacti bootstrap, as tests/Unit/ReportsShimGuardTest.php does.

Validation

  • php -l includes/functions.php — clean.
  • Simulated include of the real functions.php:
    • 1.3.0 dev (CACTI_VERSION=1.3.0): shim not loaded → core provides the natives, no redeclare.
    • 1.2.29: shim loaded from functions-pre13.php (still required there).
    • Standalone / natives predefined (the unit-test path, no version helpers): falls back to function_exists(), shim not loaded, no redeclare — ReportsShimGuardTest stays green.

@TheWitness
TheWitness requested review from bmfmancini and xmacan and a balanced review from Copilot October 9, 2026 20:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The newly introduced version-gated paths lack direct regression coverage.

1 open finding
What changed in this PR

Updates report-shim loading to avoid function redeclaration on Cacti 1.3.

Changes:

  • Gates compatibility shims using the Cacti version.
  • Retains a standalone fallback and updates the changelog.
File Description
includes/​functions.php Adds version-based shim gating.
CHANGELOG.md Documents the fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread includes/functions.php
@TheWitness
TheWitness merged commit a190463 into develop Oct 9, 2026
3 checks passed
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.

4 participants