diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php
index afb00ab123bc..95243b29bbc3 100644
--- a/CRM/Contact/BAO/Contact.php
+++ b/CRM/Contact/BAO/Contact.php
@@ -2555,7 +2555,7 @@ public static function getValues($params, &$values) {
// communication Prefferance
$preffComm = $comm = [];
$comm = explode(CRM_Core_DAO::VALUE_SEPARATOR,
- $contact->preferred_communication_method
+ ($contact->preferred_communication_method ?? '')
);
foreach ($comm as $value) {
$preffComm[$value] = 1;
diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php
index 6931364f8694..d51ae147e0ef 100644
--- a/CRM/Contact/Form/Edit/Address.php
+++ b/CRM/Contact/Form/Edit/Address.php
@@ -355,7 +355,7 @@ public static function setDefaultValues(&$defaults, &$form) {
*/
public static function storeRequiredCustomDataInfo(&$form, $groupTree) {
if (in_array(CRM_Utils_System::getClassName($form), ['CRM_Contact_Form_Contact', 'CRM_Contact_Form_Inline_Address'])) {
- $requireOmission = NULL;
+ $requireOmission = '';
foreach ($groupTree as $csId => $csVal) {
// only process Address entity fields
if ($csVal['extends'] !== 'Address') {
diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php
index 29f94c2a2ccb..4fce80faba18 100644
--- a/CRM/Core/BAO/Address.php
+++ b/CRM/Core/BAO/Address.php
@@ -774,7 +774,7 @@ public static function parseStreetAddress($streetAddress, $locale = NULL) {
// the DB to fatal
$fields = CRM_Core_BAO_Address::fields();
foreach ($fields as $fieldname => $field) {
- if (!empty($field['maxlength']) && strlen(CRM_Utils_Array::value($fieldname, $parseFields)) > $field['maxlength']) {
+ if (!empty($field['maxlength']) && strlen(($parseFields[$fieldname]) ?? '')) > $field['maxlength']) {
return $emptyParseFields;
}
}
diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php
index 2c3cd30386bf..c3f8f4a69ba2 100644
--- a/CRM/Core/BAO/CustomField.php
+++ b/CRM/Core/BAO/CustomField.php
@@ -1181,7 +1181,7 @@ private static function formatDisplayValue($value, $field, $entityId = NULL) {
// In such cases we could just get intval($value) and fetch matching
// option again, but this would not work if key is float like 5.6.
// So we need to truncate trailing zeros to make it work as expected.
- if ($display === '' && strpos($value, '.') !== FALSE) {
+ if ($display === '' && strpos(($value ?? ''), '.') !== FALSE) {
// Use round() to truncate trailing zeros, e.g:
// 10.00 -> 10, 10.60 -> 10.6, 10.69 -> 10.69.
$value = (string) round($value, 5);
diff --git a/CRM/Core/BAO/OptionGroup.php b/CRM/Core/BAO/OptionGroup.php
index 09e21694236c..deea70837f80 100644
--- a/CRM/Core/BAO/OptionGroup.php
+++ b/CRM/Core/BAO/OptionGroup.php
@@ -67,7 +67,7 @@ public static function add(&$params, $ids = []) {
if (empty($params['name']) && empty($params['id'])) {
$params['name'] = CRM_Utils_String::titleToVar(strtolower($params['title']));
}
- elseif (!empty($params['name']) && strpos($params['name'], ' ')) {
+ elseif (!empty($params['name']) && strpos(($params['name']), ' ')) {
$params['name'] = CRM_Utils_String::titleToVar(strtolower($params['name']));
}
elseif (!empty($params['name'])) {
diff --git a/CRM/Core/DAO/AllCoreTables.php b/CRM/Core/DAO/AllCoreTables.php
index 19009e09fd17..bb1e808d6a8c 100644
--- a/CRM/Core/DAO/AllCoreTables.php
+++ b/CRM/Core/DAO/AllCoreTables.php
@@ -191,7 +191,7 @@ public static function isCoreTable($tableName) {
* @return string
*/
public static function getCanonicalClassName($baoName) {
- return str_replace('_BAO_', '_DAO_', $baoName);
+ return str_replace('_BAO_', '_DAO_', ($baoName ?? ''));
}
/**
diff --git a/CRM/Core/Form/Task.php b/CRM/Core/Form/Task.php
index 1526eda1fa5b..b4003bdd3e71 100644
--- a/CRM/Core/Form/Task.php
+++ b/CRM/Core/Form/Task.php
@@ -103,7 +103,7 @@ public function setNextUrl(string $pathPart) {
}
$session = CRM_Core_Session::singleton();
- $searchFormName = strtolower($this->get('searchFormName'));
+ $searchFormName = strtolower($this->get('searchFormName') ?? '');
if ($searchFormName === 'search') {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/' . $pathPart . '/search', $urlParams));
}
diff --git a/CRM/Core/Smarty/plugins/modifier.crmNumberFormat.php b/CRM/Core/Smarty/plugins/modifier.crmNumberFormat.php
index 1a4009e916ca..3ddf4eea9b9a 100644
--- a/CRM/Core/Smarty/plugins/modifier.crmNumberFormat.php
+++ b/CRM/Core/Smarty/plugins/modifier.crmNumberFormat.php
@@ -34,7 +34,7 @@
* For alternate decimal point and thousands separator, delimit values with single quotes in the template.
* EXAMPLE: {$number|crmNumberFormat:2:',':' '} for French notation - 1234.56 becomes 1 234,56
*/
-function smarty_modifier_crmNumberFormat($number, $decimals = NULL, $dec_point = NULL, $thousands_sep = NULL) {
+function smarty_modifier_crmNumberFormat($number, $decimals = 0, $dec_point = NULL, $thousands_sep = NULL) {
if (is_numeric($number)) {
// Both dec_point AND thousands_sep are required if one is not specified
// then use the config defaults
diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php
index cec2c4425d05..874fc38a283f 100644
--- a/CRM/Financial/BAO/Payment.php
+++ b/CRM/Financial/BAO/Payment.php
@@ -191,7 +191,7 @@ public static function create(array $params): CRM_Financial_DAO_FinancialTrxn {
'is_email_receipt' => $params['is_send_contribution_notification'],
'trxn_date' => $params['trxn_date'],
'payment_instrument_id' => $paymentTrxnParams['payment_instrument_id'],
- 'payment_processor_id' => $paymentTrxnParams['payment_processor_id'] ?? NULL,
+ 'payment_processor_id' => $paymentTrxnParams['payment_processor_id'] ?? '',
]);
// Get the trxn
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php
index d7e0ac6f6edd..53fad0395968 100644
--- a/CRM/Financial/BAO/PaymentProcessor.php
+++ b/CRM/Financial/BAO/PaymentProcessor.php
@@ -100,7 +100,7 @@ public static function getCreditCards($paymentProcessorID = NULL) {
$processor = new CRM_Financial_DAO_PaymentProcessor();
$processor->id = $paymentProcessorID;
$processor->find(TRUE);
- $cards = json_decode($processor->accepted_credit_cards, TRUE);
+ $cards = json_decode(($processor->accepted_credit_cards ?? ''), TRUE);
return $cards;
}
return [];
diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php
index 002aa473b0d6..f50cff2fd12e 100644
--- a/CRM/Import/Parser.php
+++ b/CRM/Import/Parser.php
@@ -1622,7 +1622,7 @@ protected function validateCustomField($customFieldID, $value, array $fieldMetaD
*/
protected function getFieldEntity(string $fieldName) {
if ($fieldName === 'do_not_import') {
- return NULL;
+ return '';
}
if (in_array($fieldName, ['email_greeting_id', 'postal_greeting_id', 'addressee_id'], TRUE)) {
return 'Contact';
diff --git a/CRM/Logging/ReportDetail.php b/CRM/Logging/ReportDetail.php
index e026f3d4adb0..f69d6f5cd1c8 100644
--- a/CRM/Logging/ReportDetail.php
+++ b/CRM/Logging/ReportDetail.php
@@ -199,10 +199,10 @@ protected function convertDiffsToRows() {
}
// special-case for multiple values. Also works for CRM-7251: preferred_communication_method
- if ((substr($from, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
- substr($from, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR) ||
- (substr($to, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
- substr($to, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR)
+ if ((substr(($from ?? ''), 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
+ substr(($from ?? ''), -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR) ||
+ (substr(($to ?? ''), 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR &&
+ substr(($to ?? ''), -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR)
) {
$froms = $tos = [];
foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($from, CRM_Core_DAO::VALUE_SEPARATOR)) as $val) {
diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php
index 49a4d1ace2de..1649a77ff61b 100644
--- a/CRM/Report/Form.php
+++ b/CRM/Report/Form.php
@@ -1529,10 +1529,10 @@ public function addToDeveloperTab($sql) {
$this->sqlArray[] = $sql;
foreach ($this->sqlArray as $sql) {
foreach (['LEFT JOIN'] as $term) {
- $sql = str_replace($term, '
' . $term, $sql);
+ $sql = str_replace($term, '
' . $term, ($sql ?? ''));
}
foreach (['FROM', 'WHERE', 'GROUP BY', 'ORDER BY', 'LIMIT', ';'] as $term) {
- $sql = str_replace($term, '
' . $term, $sql);
+ $sql = str_replace($term, '
' . $term, ($sql ?? ''));
}
$this->sqlFormattedArray[] = $sql;
$this->assign('sql', implode(';
', $this->sqlFormattedArray));
@@ -3443,7 +3443,7 @@ public function filterStat(&$statistics) {
if (!empty($this->_params["{$fieldName}_relative"])) {
[$from, $to] = CRM_Utils_Date::getFromTo($this->_params["{$fieldName}_relative"], NULL, NULL);
}
- if (strlen($to) === 10) {
+ if (strlen($to ?? '') === 10) {
// If we just have the date we assume the end of that day.
$to .= ' 23:59:59';
}
@@ -3949,7 +3949,7 @@ public function buildACLClause($tableAlias = 'contact_a') {
public function buildPermissionClause() {
$ret = [];
foreach ($this->selectedTables() as $tableName) {
- $baoName = str_replace('_DAO_', '_BAO_', CRM_Core_DAO_AllCoreTables::getClassForTable($tableName));
+ $baoName = str_replace('_DAO_', '_BAO_', (CRM_Core_DAO_AllCoreTables::getClassForTable($tableName) ?? ''));
if ($baoName && class_exists($baoName) && !empty($this->_columns[$tableName]['alias'])) {
$tableAlias = $this->_columns[$tableName]['alias'];
$clauses = array_filter($baoName::getSelectWhereClause($tableAlias));
diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php
index 48fb0c7c48e7..960f03d9c1c3 100644
--- a/CRM/Utils/Date.php
+++ b/CRM/Utils/Date.php
@@ -346,7 +346,7 @@ public static function customFormat($dateString, $format = NULL, $dateParts = NU
$day = (int) substr(($dateString ?? ''), 6, 2);
}
- if (strlen($dateString) > 10) {
+ if (strlen(($dateString ?? '')) > 10) {
$format = $config->dateformatDatetime;
}
elseif ($day > 0) {
@@ -481,12 +481,12 @@ public static function customFormatTs($timestamp, $format = NULL, $dateParts = N
* date/datetime in ISO format
*/
public static function mysqlToIso($mysql) {
- $year = substr($mysql, 0, 4);
- $month = substr($mysql, 4, 2);
- $day = substr($mysql, 6, 2);
- $hour = substr($mysql, 8, 2);
- $minute = substr($mysql, 10, 2);
- $second = substr($mysql, 12, 2);
+ $year = substr(($mysql ?? ''), 0, 4);
+ $month = substr(($mysql ?? ''), 4, 2);
+ $day = substr(($mysql ?? ''), 6, 2);
+ $hour = substr(($mysql ?? ''), 8, 2);
+ $minute = substr(($mysql ?? ''), 10, 2);
+ $second = substr(($mysql ?? ''), 12, 2);
$iso = '';
if ($year) {
diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php
index 0e62e265147c..675709e9e63d 100644
--- a/CRM/Utils/File.php
+++ b/CRM/Utils/File.php
@@ -446,9 +446,9 @@ public static function makeFileName($name) {
$uniqID = md5(uniqid(rand(), TRUE));
$info = pathinfo($name);
$basename = substr($info['basename'],
- 0, -(strlen(CRM_Utils_Array::value('extension', $info)) + (CRM_Utils_Array::value('extension', $info) == '' ? 0 : 1))
+ 0, -(strlen(CRM_Utils_Array::value('extension', $info, '')) + (CRM_Utils_Array::value('extension', $info, '') == '' ? 0 : 1))
);
- if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info))) {
+ if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info, ''))) {
// munge extension so it cannot have an embbeded dot in it
// The maximum length of a filename for most filesystems is 255 chars.
// We'll truncate at 240 to give some room for the extension.
@@ -1058,7 +1058,7 @@ public static function getIconFromMimeType($mimeType) {
}
$iconClasses = Civi::$statics[__CLASS__]['mimeIcons'];
foreach ($iconClasses as $text => $icon) {
- if (strpos($mimeType, $text) === 0) {
+ if (strpos(($mimeType ?? ''), $text) === 0) {
return $icon;
}
}
@@ -1128,6 +1128,9 @@ public static function getExtensionFromPath($path) {
* In php8 the return value from is_dir() is always bool but in php7 it can be null.
*/
public static function isDir(?string $dir) {
+ if ($dir === NULL) {
+ return FALSE;
+ }
set_error_handler(function($errno, $errstr) {
// If this is open_basedir-related, convert it to an exception so we
// can catch it.
diff --git a/CRM/Utils/Mail.php b/CRM/Utils/Mail.php
index beb0ad3263b8..b649373d65f8 100644
--- a/CRM/Utils/Mail.php
+++ b/CRM/Utils/Mail.php
@@ -451,7 +451,7 @@ public static function setMimeParams($message, $params = NULL) {
public static function formatRFC822Email($name, $email, $useQuote = FALSE) {
$result = NULL;
- $name = trim($name);
+ $name = trim($name ?? '');
// strip out double quotes if present at the beginning AND end
if (substr($name, 0, 1) == '"' &&
diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php
index e0bcfc01179a..f1e6cc6d028e 100644
--- a/CRM/Utils/System.php
+++ b/CRM/Utils/System.php
@@ -213,7 +213,7 @@ public static function makeQueryString($query) {
if (is_array($query)) {
$buf = '';
foreach ($query as $key => $value) {
- $buf .= ($buf ? '&' : '') . urlencode($key) . '=' . urlencode($value);
+ $buf .= ($buf ? '&' : '') . urlencode($key ?? '') . '=' . urlencode($value ?? '');
}
$query = $buf;
}
diff --git a/api/v3/CustomValue.php b/api/v3/CustomValue.php
index 72ef10ab59d8..9efe097af787 100644
--- a/api/v3/CustomValue.php
+++ b/api/v3/CustomValue.php
@@ -172,7 +172,7 @@ function civicrm_api3_custom_value_get($params) {
// Convert multi-value strings to arrays
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
foreach ($result as $id => $value) {
- if (strpos($value, $sp) !== FALSE) {
+ if (strpos(($value ?? ''), $sp) !== FALSE) {
$value = explode($sp, trim($value, $sp));
}
diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php
index c7ec5be82823..9aaaf67df80e 100644
--- a/api/v3/Mailing.php
+++ b/api/v3/Mailing.php
@@ -618,7 +618,7 @@ function civicrm_api3_mailing_send_test($params) {
$job = civicrm_api3('MailingJob', 'create', $testEmailParams);
CRM_Mailing_BAO_Mailing::getRecipients($testEmailParams['mailing_id']);
$testEmailParams['job_id'] = $job['id'];
- $testEmailParams['emails'] = array_key_exists('test_email', $testEmailParams) ? explode(',', strtolower($testEmailParams['test_email'])) : NULL;
+ $testEmailParams['emails'] = array_key_exists('test_email', $testEmailParams) ? explode(',', strtolower($testEmailParams['test_email'] ?? '')) : NULL;
if (!empty($params['test_email'])) {
$query = CRM_Utils_SQL_Select::from('civicrm_email e')
->select(['e.id', 'e.contact_id', 'e.email'])
diff --git a/api/v3/Profile.php b/api/v3/Profile.php
index a20bd48e1e81..6afa73b30aa1 100644
--- a/api/v3/Profile.php
+++ b/api/v3/Profile.php
@@ -193,7 +193,7 @@ function civicrm_api3_profile_submit($params) {
$contactEntities = ['contact', 'individual', 'organization', 'household'];
$locationEntities = ['email', 'address', 'phone', 'website', 'im'];
- $entity = strtolower(CRM_Utils_Array::value('entity', $field));
+ $entity = strtolower(CRM_Utils_Array::value('entity', $field, ''));
if ($entity && !in_array($entity, array_merge($contactEntities, $locationEntities))) {
switch ($entity) {
case 'note':
diff --git a/api/v3/utils.php b/api/v3/utils.php
index c2e25c92fda6..d454535bfe1d 100644
--- a/api/v3/utils.php
+++ b/api/v3/utils.php
@@ -1777,7 +1777,7 @@ function _civicrm_api3_validate_constraint($fieldValue, $fieldName, $fieldInfo,
*/
function _civicrm_api3_validate_unique_key(&$params, &$fieldName) {
[$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
- if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ if (strpos(($op ?? ''), 'NULL') !== FALSE || strpos(($op ?? ''), 'EMPTY') !== FALSE) {
return;
}
$existing = civicrm_api($params['entity'], 'get', [
@@ -2217,7 +2217,7 @@ function _civicrm_api3_resolve_contactID($contactIdExpr) {
*/
function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) {
[$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName);
- if (strpos($op, 'NULL') || strpos($op, 'EMPTY')) {
+ if (strpos(($op ?? ''), 'NULL') || strpos(($op ?? ''), 'EMPTY')) {
return;
}
}