Skip to content

Guard pre-1.3 report shims with function_exists to avoid redeclare fatal - #288

Merged
TheWitness merged 2 commits into
developfrom
fix/pre13-reports-shim-redeclare
Oct 8, 2026
Merged

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

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Problem

includes/functions.php loads the pre-1.3 report compatibility shims with a
version-string gate:

if (version_compare(CACTI_VERSION, '1.3', '<')) {
    require_once(__DIR__ . '/functions-pre13.php');
}

functions-pre13.php unconditionally defines reports_run(),
reports_queue(), and reports_log_and_notify(). Cacti core defines all three
natively in lib/reports.php on 1.3. Current develop builds still report a
version that compares < 1.3, so this block loads the shims even though the
native functions already exist, producing a Cannot redeclare reports_run()
fatal
on flowview's report pages and the report poller.

This is the same unreliable CACTI_VERSION gating that was just fixed in
plugin_monitor (#270); here it surfaces as a hard fatal rather than a UI hang.

Fix

Gate on the actual presence of the functions rather than the version string.
Core adds all three together, so checking the representative reports_run() is
sufficient:

if (!function_exists('reports_run')) {
    require_once(__DIR__ . '/functions-pre13.php');
}
  • True legacy Cacti (< 1.3, functions absent): shims load as before.
  • Cacti 1.3 and any develop build that reports < 1.3 while already defining
    the functions natively: shims are skipped, no redeclare.

functions-pre13.php is loaded only from this one site (verified), so no other
include path can trip the redeclare.

Testing

  • php -l includes/functions.php — no syntax errors.

@TheWitness
TheWitness requested review from bmfmancini and xmacan and a balanced review from Copilot October 8, 2026 18:52
functions-pre13.php unconditionally defines reports_run/reports_queue/reports_log_and_notify, which are native in Cacti 1.3. A develop build can report a version comparing < 1.3 while already defining them, so the version_compare gate loaded the shims and fatally redeclared them. Gate on function_exists('reports_run') instead.
@TheWitness
TheWitness force-pushed the fix/pre13-reports-shim-redeclare branch from 4e8688e to 777b42d Compare October 8, 2026 18:54

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 develop-only redeclaration scenario lacks targeted regression coverage.

1 open finding
What changed in this PR

Updates report compatibility loading to avoid function redeclaration failures on Cacti develop builds.

Changes:

  • Replaces version-based shim loading with a function_exists() guard.
  • Documents the fix in the changelog.
File Description
includes/​functions.php Guards legacy report shims using runtime function availability.
CHANGELOG.md Records the compatibility 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
xmacan
xmacan previously approved these changes Oct 8, 2026
…elpers

Addresses PR review: CI checks out Cacti 1.2.x (report helpers absent) and the bootstrap already loaded functions.php, so the develop-only 'natives present' path is not covered in-process. Add an isolated child-process test that defines reports_run/reports_queue/reports_log_and_notify, requires functions.php, and asserts it loads without a redeclaration.
@TheWitness
TheWitness merged commit 71388b9 into develop Oct 8, 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.

3 participants