Skip to content

Commit 4253b17

Browse files
fix(compat): replace str_starts_with with strncmp for PHP 7.4
PhpSyntaxTest.php used str_starts_with() (PHP 8.0+) which would fatal under PHP 7.4 before any assertion ran. Use strncmp() instead. Also remove redundant (int) cast and double in_array check on drp_action in notify_lists.php: get_filter_request_var() already validated the value; the second clause was dead and confusing. Replace count() with cacti_sizeof() in setup.php bulk loop. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent f8ca477 commit 4253b17

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

notify_lists.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ function form_actions() {
150150

151151
$valid_actions = array_keys($actions + $assoc_actions);
152152

153-
if (!in_array(get_request_var('drp_action'), $valid_actions, true) &&
154-
!in_array((int) get_request_var('drp_action'), $valid_actions, true)) {
153+
if (!in_array(get_request_var('drp_action'), $valid_actions, true)) {
155154
raise_message(40);
156155
header('Location: notify_lists.php');
157156
exit;

setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ function thold_device_action_execute($action) {
691691
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
692692

693693
if ($selected_items != false) {
694-
for ($i = 0; ($i < count($selected_items)); $i++) {
694+
for ($i = 0; ($i < cacti_sizeof($selected_items)); $i++) {
695695
autocreate($selected_items[$i]);
696696
}
697697
}

tests/Smoke/PhpSyntaxTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
$rel = ltrim(str_replace($root, '', $file->getPathname()), DIRECTORY_SEPARATOR);
3232

33-
if (str_starts_with($rel, 'vendor' . DIRECTORY_SEPARATOR)) {
33+
if (strncmp($rel, 'vendor' . DIRECTORY_SEPARATOR, strlen('vendor' . DIRECTORY_SEPARATOR)) === 0) {
3434
continue;
3535
}
3636

37-
if (str_starts_with($rel, 'tests' . DIRECTORY_SEPARATOR)) {
37+
if (strncmp($rel, 'tests' . DIRECTORY_SEPARATOR, strlen('tests' . DIRECTORY_SEPARATOR)) === 0) {
3838
continue;
3939
}
4040

0 commit comments

Comments
 (0)