Skip to content

fix: declare PHP 8.1 as the minimum and accept non-array payloads in chained hooks - #973

Merged
TheWitness merged 3 commits into
Cacti:developfrom
somethingwithproof:fix/php-floor-hook-chain-types
Dec 5, 2026
Merged

TheWitness merged 3 commits into
Cacti:developfrom
somethingwithproof:fix/php-floor-hook-chain-types

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Problem

Two regressions from the type clean-up in #970, described in #972.

  • The PHP minimum is not declared. The native types added in refactor: clear PHPStan level 6 findings and declare native types on every function #970 do not parse on PHP 7.4, which Cacti 1.2.29 - 1.2.31 still accept, and setup.php loads on every page, so such a site shows a blank page after updating. INFO declares only the Cacti version and the README defers to Cacti.
  • Chained hook callbacks typed array throw a TypeError when a plugin earlier in Cacti's hook chain returns nothing, because api_plugin_hook_function() passes each plugin the previous plugin's return value. thold_draw_navigation_text() runs on every page.

Change

  • Declare PHP 8.1 as the minimum: php = 8.1 in INFO, a README requirements section and CHANGELOG entries. Linting every production PHP file gives 22 failures on PHP 7.4 and none on 8.0, 8.1 or 8.2; the never return type makes 8.1 the real minimum. Cacti has no PHP requirement field, but it honours a false return from plugin_thold_install() (hooks left disabled) and plugin_thold_check_config() (enable refused). Both, and thold_check_dependencies(), now refuse through thold_php_supported() and log why. This can only act where setup.php still parses (PHP 8.0); on PHP 7.4 nothing in the plugin can run, so that case is covered by documentation only. The CI matrix covers PHP 8.2 and later, so 8.1 is the declared floor rather than a tested one.
  • Take mixed in the ten chained callbacks (the eight named in PHP minimum undeclared after #970; chained hook callbacks throw TypeError on a non-array #972 plus thold_data_source_action_array() and thold_graphs_action_array()). thold_draw_navigation_text(), the three action array callbacks and thold_clog_regex_array() start from an empty array; thold_data_sources_table(), thold_rrd_graph_graph_options(), thold_api_device_save(), thold_user_admin_setup_sql_save() and thold_data_source_remove() return a non-array unchanged and do no work. No other types are loosened.

Verification

  • tests/Unit/PhpFloorTest.php and tests/Unit/HookChainTolerantInputTest.php were written first: 44 failed against develop (10 more for the two action array callbacks, added later) (undefined floor functions, TypeError on null, false, a string and an int in each callback), all pass with the change.
  • Pest Unit suite 1035 passed and Behaviour suite 1430 passed (22 skipped) on PHP 8.2 and on PHP 8.6.
  • PHPStan level 6 with Cacti's configuration: no errors, before and after.
  • Patch coverage gate: 100% (23/23 changed lines) locally.
  • A real PHP 8.0 interpreter loading setup.php gets false from all three checks and a log line naming 8.1 and the running version.
  • php -l over the 48 production PHP files: 22 failures on 7.4, none on 8.0, 8.1 or 8.2.

Fixes #972

…chained hooks

The native types added in Cacti#970 do not parse on PHP 7.4, which Cacti 1.2.29
to 1.2.31 still accept, and setup.php loads on every page. Declare
php = 8.1 in INFO and the README, and make plugin_thold_install(),
plugin_thold_check_config() and thold_check_dependencies() refuse on an
older PHP that can still read the file, logging the reason.

Cacti hands each plugin the previous plugin's return value, so a plugin
earlier in the chain that returns nothing made the array-typed callbacks
throw a TypeError. The navigation, device action and clog regex callbacks
now start from an empty array; the data source table, graph options,
device save, user save and data source remove callbacks return a
non-array unchanged.

Fixes Cacti#972

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…1.2.31

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…rray hooks

Core chains data_source_action_array and graphs_action_array with
api_plugin_hook_function(), so a plugin earlier in the chain that returns
nothing leaves null for these callbacks. Start from an empty array, as the
device action callback does. The other registered hooks are either typed
nullable already, take no payload, or are called with api_plugin_hook()
and a fresh array, which does not chain.

Refs Cacti#972

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit ed6b6c1 into Cacti:develop Dec 5, 2026
7 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.

PHP minimum undeclared after #970; chained hook callbacks throw TypeError on a non-array

2 participants