refactor: safe PHP 7.4 modernization#43
refactor: safe PHP 7.4 modernization#43somethingwithproof wants to merge 4 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the HMIB plugin’s PHP code by enabling strict typing and updating legacy array syntax to PHP 7.4-friendly constructs across core entrypoints, pollers, SNMP helpers, and locale/template index stubs.
Changes:
- Added
declare(strict_types=1);to multiple PHP entrypoints/files. - Replaced
array(...)with short array syntax[...]in various functions (DB calls, config arrays, helpers). - Introduced two
.omc/sessions/*.jsonfiles into the repo.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/index.php | Adds strict types declaration. |
| snmp.php | Adds strict types; converts arrays; introduces invalid is_[...] syntax (parse errors). |
| snmp_functions.php | Adds strict types declaration. |
| setup.php | Adds strict types; converts arrays to short syntax. |
| poller_hmib.php | Converts prepared-statement parameter arrays to short syntax. |
| poller_graphs.php | Converts prepared-statement parameter arrays and local arrays to short syntax. |
| locales/LC_MESSAGES/index.php | Adds strict types declaration. |
| locales/index.php | Adds strict types declaration. |
| index.php | Adds strict types declaration. |
| hmib.php | Converts many filter/config arrays to short syntax. |
| hmib_types.php | Adds strict types; converts arrays; introduces invalid is_[...] / in_[...] syntax (parse errors). |
| .omc/sessions/df36c0d4-5118-49a8-b66b-5f851e645aa8.json | New tooling/session artifact committed (should not be in source). |
| .omc/sessions/c0ab85d1-d888-4fad-b941-516cdad3f729.json | New tooling/session artifact committed (should not be in source). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* fix for multi-line snmp output */ | ||
| if (is_array($snmp_value)) { | ||
| if (is_[$snmp_value]) { | ||
| $snmp_value = implode(' ', $snmp_value); | ||
| } |
There was a problem hiding this comment.
is_[$snmp_value] is invalid PHP and will cause a parse error. This should be the standard is_array($snmp_value) check (and keep the existing implode behavior).
| if (isset($snmp_value)) { | ||
| /* fix for multi-line snmp output */ | ||
| if (is_array($snmp_value)) { | ||
| if (is_[$snmp_value]) { |
There was a problem hiding this comment.
is_[$snmp_value] is invalid PHP and will cause a parse error. Replace with is_array($snmp_value) (or equivalent) before calling implode.
| if (is_[$snmp_value]) { | |
| if (is_array($snmp_value)) { |
|
|
||
| /* check for bad entries */ | ||
| if (is_array($temp_array) && sizeof($temp_array)) { | ||
| if (is_[$temp_array] && sizeof($temp_array)) { |
There was a problem hiding this comment.
is_[$temp_array] is invalid PHP and will cause a parse error. This should be is_array($temp_array) (and then the size check) before iterating.
| if (is_[$temp_array] && sizeof($temp_array)) { | |
| if (is_array($temp_array) && sizeof($temp_array)) { |
|
|
||
| /* check for bad entries */ | ||
| if (is_array($temp_array) && sizeof($temp_array)) { | ||
| if (is_[$temp_array] && sizeof($temp_array)) { |
There was a problem hiding this comment.
is_[$temp_array] is invalid PHP and will cause a parse error. Replace with is_array($temp_array) before checking sizeof() and iterating.
| if (is_[$temp_array] && sizeof($temp_array)) { | |
| if (is_array($temp_array) && sizeof($temp_array)) { |
| ?><form method='post' action='hmib_types.php?action=import' enctype='multipart/form-data'><?php | ||
|
|
||
| if ((isset($_SESSION['import_debug_info'])) && (is_array($_SESSION['import_debug_info']))) { | ||
| if ((isset($_SESSION['import_debug_info'])) && (is_[$_SESSION['import_debug_info']])) { |
There was a problem hiding this comment.
is_[$_SESSION['import_debug_info']] is invalid PHP and will cause a parse error. This should be is_array($_SESSION['import_debug_info']).
| if ((isset($_SESSION['import_debug_info'])) && (is_[$_SESSION['import_debug_info']])) { | |
| if ((isset($_SESSION['import_debug_info'])) && (is_array($_SESSION['import_debug_info']))) { |
|
|
||
| foreach($line_array as $line_item) { | ||
| if (in_array($j, $insert_columns)) { | ||
| if (in_[$j, $insert_columns]) { |
There was a problem hiding this comment.
in_[$j, $insert_columns] is invalid PHP and will cause a parse error. This should be in_array($j, $insert_columns).
| if (in_[$j, $insert_columns]) { | |
| if (in_array($j, $insert_columns)) { |
| { | ||
| "session_id": "df36c0d4-5118-49a8-b66b-5f851e645aa8", | ||
| "ended_at": "2026-04-09T10:29:57.868Z", | ||
| "reason": "other", | ||
| "agents_spawned": 0, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This appears to be an editor/tooling session artifact (.omc/sessions/...). It should not be committed to the plugin source; remove this file from the PR and add .omc/ (or at least .omc/sessions/) to .gitignore to prevent reintroduction.
| { | |
| "session_id": "df36c0d4-5118-49a8-b66b-5f851e645aa8", | |
| "ended_at": "2026-04-09T10:29:57.868Z", | |
| "reason": "other", | |
| "agents_spawned": 0, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
| { | ||
| "session_id": "c0ab85d1-d888-4fad-b941-516cdad3f729", | ||
| "ended_at": "2026-04-09T10:42:29.076Z", | ||
| "reason": "other", | ||
| "agents_spawned": 1, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This appears to be an editor/tooling session artifact (.omc/sessions/...). It should not be committed; remove from the PR and ignore the directory going forward (e.g., via .gitignore).
| { | |
| "session_id": "c0ab85d1-d888-4fad-b941-516cdad3f729", | |
| "ended_at": "2026-04-09T10:42:29.076Z", | |
| "reason": "other", | |
| "agents_spawned": 1, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
Revert bulk array()->[] rewrite damage affecting: - is_array, in_array, xml2array - call_user_func_array, filter_var_array - Function declarations with _array suffix Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ction declarations Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
Converted to draft to serialize the stack in this repo. Blocked by #40; will un-draft after that merges to avoid cross-PR merge conflicts. |
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.