Skip to content

Commit 2616a25

Browse files
committed
Fix issue #7956: PHP 8 compatibility for custom field integer types
PHP 8 changed loose comparison behavior: '' != 0 is now true (was false in PHP 7). This caused empty custom field values to be written as '' instead of NULL for integer/list columns (types 8, 9, 12), triggering MySQL error: 'Incorrect integer value: '' for column' Changes: - Functions.php: Replace loose comparison with explicit empty/null/zero checks in sqlCustomField(); cast values to (int) for safer integer column inserts - InputUtils.php: legacyFilterInput() now returns type-appropriate empty values (0 for int, 0.0 for float) instead of always returning '' Affects: FamilyEditor, PersonEditor, GroupPropsEditor, CSVImport
1 parent ddaf790 commit 2616a25

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/ChurchCRM/utils/InputUtils.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,16 @@ public static function legacyFilterInput($sInput, $type = 'string', $size = 1)
182182
throw new \InvalidArgumentException('Invalid "type" for legacyFilterInput provided');
183183
}
184184
} else {
185-
return '';
185+
// PHP 8 compatibility: return type-appropriate empty values
186+
// to avoid loose comparison issues (e.g., '' != 0 is true in PHP 8)
187+
switch ($type) {
188+
case 'int':
189+
return 0;
190+
case 'float':
191+
return 0.0;
192+
default:
193+
return '';
194+
}
186195
}
187196
}
188197
}

src/Include/Functions.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,12 @@ function sqlCustomField(string &$sSQL, $type, $data, string $col_Name, $special)
937937
// list selects
938938
case 9:
939939
case 12:
940-
if ($data != 0) {
941-
$sSQL .= $col_Name . " = '" . $data . "', ";
942-
} else {
940+
// PHP 8 changed loose comparison: '' != 0 is now true (was false in PHP 7)
941+
// Explicitly check for empty string/null/zero to maintain original behavior
942+
if ($data === '' || $data === null || (int) $data === 0) {
943943
$sSQL .= $col_Name . ' = NULL, ';
944+
} else {
945+
$sSQL .= $col_Name . " = '" . (int) $data . "', ";
944946
}
945947
break;
946948

0 commit comments

Comments
 (0)