From 77e6b3adc3178b7e1980e8f965662dc1194643d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 6 May 2022 14:35:18 +0200 Subject: [PATCH] fix: deprecated nullish value as string on PHP8.1 M2-97 - Fixed some "Passing null to parameter of type string is deprecated" problems for PHP 8.1 compatibility (#27) --- src/Model/Request/SubModel/AbstractModel.php | 2 +- src/Service/SimpleXmlExtended.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Model/Request/SubModel/AbstractModel.php b/src/Model/Request/SubModel/AbstractModel.php index c143247..7e86570 100644 --- a/src/Model/Request/SubModel/AbstractModel.php +++ b/src/Model/Request/SubModel/AbstractModel.php @@ -200,7 +200,7 @@ public function toArray() } } else { if (key_exists('cdata', $fieldSettings)) { // If value should be encapsulated inside CDATA tag - if (function_exists('mb_detect_encoding') && !mb_detect_encoding($fieldSettings['value'], 'UTF-8', true)) { // Check only if php mdstring extension is loaded + if (function_exists('mb_detect_encoding') && is_string($fieldSettings['value']) && !mb_detect_encoding($fieldSettings['value'], 'UTF-8', true)) { // Check only if php mdstring extension is loaded throw new ModelException("Value of '" . $fieldName . "' has to be encoded in UTF-8"); } } diff --git a/src/Service/SimpleXmlExtended.php b/src/Service/SimpleXmlExtended.php index 4c309d6..bc18043 100644 --- a/src/Service/SimpleXmlExtended.php +++ b/src/Service/SimpleXmlExtended.php @@ -41,6 +41,10 @@ public function addCDataChild($sName, $sValue) */ private function removeSpecialChars($str) { + if (!is_string($str)) { + return ''; + } + $search = ['–', '´', '‹', '›', '‘', '’', '‚', '“', '”', '„', '‟', '•', '‒', '―', '—', '™', '¼', '½', '¾']; $replace = ['-', "'", '<', '>', "'", "'", ',', '"', '"', '"', '"', '-', '-', '-', '-', 'TM', '1/4', '1/2', '3/4'];