Smarty - Fix warnings about 'mb_truncate' modifier
authorTim Otten <totten@civicrm.org>
Thu, 23 Feb 2023 20:43:30 +0000 (12:43 -0800)
committerTim Otten <totten@civicrm.org>
Thu, 23 Feb 2023 20:43:30 +0000 (12:43 -0800)
Steps to reproduce
------------------

* Use PHP 8.1 and D7 with a default logging policy (eg "All Messages" or "Errors and Warnings")
* Use "Search > Find Contacts"
* On the listing page, observe a bunch of warnings

Before
------

~25 warnings, including ~10 related to modifier.mb_truncate.php

After
-----

~10 warnings, none involving `mb_truncate`

CRM/Core/Smarty/plugins/modifier.mb_truncate.php

index a58909ff0592fa25ce9a5033783fa901558233f2..6f81841d42075d7053f5f464f860f79f9755b48b 100644 (file)
@@ -58,7 +58,7 @@ function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...',
 
   }
 
-  if ($strlen($string) > $length) {
+  if ($strlen($string ?: '') > $length) {
     $length -= $strlen($etc);
     if (!$break_words) {
       $string = preg_replace('/\s+?(\S+)?$/', '', $substr($string, 0, $length + 1));