refactor: safe PHP 7.4 modernization#91
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the GPSMap plugin’s PHP codebase for PHP 7.4 by enabling strict typing and updating older PHP syntax (notably array literals) across runtime and setup/polling/test entrypoints.
Changes:
- Added
declare(strict_types=1);across many plugin PHP files. - Replaced long
array(...)syntax with short[...]syntax in several code paths. - Updated miscellaneous scaffolding/redirect
index.phpfiles and added a new.omcsession file.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| XML/index.php | Add strict_types to redirect stub. |
| tests/test_functions.php | Add strict_types and modernize stubbed return arrays. |
| setup.php | Add strict_types and convert several arrays to [...]. |
| print.php | Add strict_types. |
| locales/po/index.php | Add strict_types to redirect stub. |
| locales/LC_MESSAGES/index.php | Add strict_types to redirect stub. |
| locales/index.php | Add strict_types to redirect stub. |
| js/index.php | Add strict_types to redirect stub. |
| index.php | Add strict_types to redirect stub. |
| includes/towerSelect.php | Add strict_types. |
| includes/setup/tabs.php | Add strict_types. |
| includes/setup/show.php | Add strict_types. |
| includes/setup/settings.php | Add strict_types. |
| includes/setup/index.php | Add strict_types to redirect stub. |
| includes/setup/gpsmapinitial.php | Add strict_types. |
| includes/setup/database.php | Add strict_types and modernize arrays to [...]. |
| includes/polling/processregion.php | Add strict_types and modernize arrays to [...]. |
| includes/polling/pollinginitial.php | Add strict_types. |
| includes/polling/kmlcreation.php | Add strict_types and convert array initialization to []. |
| includes/polling/index.php | Add strict_types to redirect stub. |
| includes/polling/iconskml.php | Add strict_types. |
| includes/polling/functions.php | Add strict_types and convert array initialization to []. |
| includes/polling/coveragexml.php | Add strict_types. |
| includes/polling.php | Add strict_types and modernize arrays to [...]. |
| includes/index.php | Add strict_types to redirect stub. |
| includes/icons.php | Add strict_types. |
| includes/customicons.php | Add strict_types and convert array initialization to []. |
| images/index.php | Add strict_types to redirect stub. |
| images/icons/index.php | Add strict_types to redirect stub. |
| gpstemplates.php | Add strict_types and modernize several arrays to [...]. |
| gpsmap.php | Add strict_types. |
| class/index.php | Add strict_types to redirect stub. |
| class/hosts_class.php | Add strict_types. |
| .omc/sessions/4ee8eaf0-d41c-4923-be60-f215905313bd.json | New session metadata file added to repo. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!function_exists('cacti_sizeof')) { | ||
| function cacti_sizeof($var) { return is_array($var) ? count($var) : 0; } | ||
| function cacti_sizeof($var) { return is_[$var] ? count($var) : 0; } | ||
| } |
There was a problem hiding this comment.
cacti_sizeof() stub uses is_[$var], which is invalid PHP and will cause a parse error when running the tests. This should be is_array($var) (and consider returning count($var) only for arrays).
| $group = $row['groupnum']; | ||
|
|
||
| if (in_array($row['host_template_id'], $towerIds)) { | ||
| if (in_[$row['host_template_id'], $towerIds]) { |
There was a problem hiding this comment.
in_[$row['host_template_id'], $towerIds] is invalid PHP syntax and will cause a parse error. Replace with in_array($row['host_template_id'], $towerIds, true) (or non-strict if required by existing data types).
| if (in_[$row['host_template_id'], $towerIds]) { | |
| if (in_array($row['host_template_id'], $towerIds, true)) { |
| switch ($preempt) { | ||
| case 0: | ||
| if (!in_array($first . '.', $iparray)) { | ||
| if (!in_[$first . '.', $iparray]) { | ||
| $iparray[] = $first.'.'; |
There was a problem hiding this comment.
if (!in_[$first . '.', $iparray]) is invalid PHP syntax and will fail at runtime. Use in_array($first . '.', $iparray, true) instead.
| case 1: | ||
| if (!strcasecmp($subnet, $first . '.')) { | ||
| if (!in_array($first . '.' . $second . '.', $iparray)) { | ||
| if (!in_[$first . '.' . $second . '.', $iparray]) { | ||
| $iparray[] = $first . '.' . $second . '.'; | ||
| } |
There was a problem hiding this comment.
if (!in_[$first . '.' . $second . '.', $iparray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.' . $second . '.', $iparray, true).
| case 2: | ||
| if (!strcasecmp($subnet, $first . '.' . $second . '.')) { | ||
| if (!in_array($first . '.' . $second . '.' . $third . '.', $iparray)) { | ||
| if (!in_[$first . '.' . $second . '.' . $third . '.', $iparray]) { | ||
| $iparray[] = $first . '.' . $second . '.' . $third . '.'; | ||
| } |
There was a problem hiding this comment.
if (!in_[$first . '.' . $second . '.' . $third . '.', $iparray]) is invalid PHP syntax and will not parse. Use in_array($first . '.' . $second . '.' . $third . '.', $iparray, true).
| break; | ||
| case 3: | ||
| if (!strcasecmp($subnet, $first . '.' . $second . '.' . $third . '.')) { | ||
| if (!in_array($first . '.' . $second . '.' . $third . '.' . $fourth . '.' , $iparray)) { | ||
| if (!in_[$first . '.' . $second . '.' . $third . '.' . $fourth . '.' , $iparray]) { | ||
| $iparray[] = $first . '.' . $second . '.' . $third . '.' . $fourth; | ||
| $ipwriteout[] = '<a href="' . $config['url_path'] . 'graph_view.php?action=preview&reset=1&host_id=' . $host->id. '">' . __('IP %s', $first . '.' . $second . '.' . $third . '.' . $fourth) . '</a><br/>'; |
There was a problem hiding this comment.
if (!in_[$first . '.' . $second . '.' . $third . '.' . $fourth . '.' , $iparray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.' . $second . '.' . $third . '.' . $fourth . '.', $iparray, true) (note consistent trailing dot handling).
|
|
||
| if (!in_array($first . '.', $firstArray)){ | ||
| if (!in_[$first . '.', $firstArray]){ | ||
| $firstArray[] = $first . '.'; | ||
| } |
There was a problem hiding this comment.
if (!in_[$first . '.', $firstArray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.', $firstArray, true) (or non-strict if needed).
|
|
||
| if (!in_array($first . '.' . $second . '.', $secondArray)){ | ||
| if (!in_[$first . '.' . $second . '.', $secondArray]){ | ||
| $secondArray[] = $first . '.' . $second . '.'; | ||
| } |
There was a problem hiding this comment.
if (!in_[$first . '.' . $second . '.', $secondArray]) is invalid PHP syntax and will not parse. Replace with in_array($first . '.' . $second . '.', $secondArray, true).
|
|
||
| if (!in_array($first . '.' . $second . '.' . $third . '.', $thirdArray)){ | ||
| if (!in_[$first . '.' . $second . '.' . $third . '.', $thirdArray]){ | ||
| $thirdArray[] = $first . '.' . $second . '.' . $third . '.'; | ||
| } |
There was a problem hiding this comment.
if (!in_[$first . '.' . $second . '.' . $third . '.', $thirdArray]) is invalid PHP syntax and will cause a parse error. Replace with in_array($first . '.' . $second . '.' . $third . '.', $thirdArray, true).
| { | ||
| "session_id": "4ee8eaf0-d41c-4923-be60-f215905313bd", | ||
| "ended_at": "2026-04-09T20:28:55.668Z", | ||
| "reason": "other", | ||
| "agents_spawned": 1, | ||
| "agents_completed": 0, | ||
| "modes_used": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
This looks like a local tooling/session artifact (.omc/sessions/...json) and likely shouldn’t be committed. Please remove it from the PR and add .omc/ (or at least .omc/sessions/) to the project’s ignore rules so it doesn’t get re-added.
| { | |
| "session_id": "4ee8eaf0-d41c-4923-be60-f215905313bd", | |
| "ended_at": "2026-04-09T20:28:55.668Z", | |
| "reason": "other", | |
| "agents_spawned": 1, | |
| "agents_completed": 0, | |
| "modes_used": [] | |
| } |
Revert corrupted function calls introduced by refactoring tool: - is_[$x] -> is_array($x) - in_[$x, ...] -> in_array($x, ...) - xml2[$x] -> xml2array($x) Also remove accidentally committed .omc session files and add .omc/ to .gitignore. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
This PR adds strict typing, short array syntax, and null coalescing operators across the plugin. Standalone infrastructure files were removed per architectural mandate.