summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wisselink <s.wisselink@iwink.nl>2022-02-06 22:20:05 +0100
committerSimon Wisselink <s.wisselink@iwink.nl>2022-02-06 22:20:05 +0100
commit3cc56392c60c501388dffe9f6afb723b46a2864b (patch)
treedb402c78089cf9fc05ca1f4fa22037eb7b7eb4da
parent17025423e1e88baaaf7651f34ab8e3cd16fba1ab (diff)
downloadsmarty-3cc56392c60c501388dffe9f6afb723b46a2864b.tar.gz
smarty-3cc56392c60c501388dffe9f6afb723b46a2864b.tar.bz2
smarty-3cc56392c60c501388dffe9f6afb723b46a2864b.zip
prevent float to int cast deprecation warning in truncate modifier
Fixes #699
-rw-r--r--CHANGELOG.md3
-rw-r--r--libs/plugins/modifier.truncate.php6
2 files changed, 5 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 695c17f8..bb500102 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
-- PHP 8.1 deprecation notices in demo/plugins/cacheresource.pdo.php [#706](https://github.com/smarty-php/smarty/issues/706)
+- PHP 8.1 deprecation notices in demo/plugins/cacheresource.pdo.php [#706](https://github.com/smarty-php/smarty/issues/706)
+- PHP 8.1 deprecation notices in truncate modifier [#699](https://github.com/smarty-php/smarty/issues/699)
## [4.1.0] - 2022-02-06
diff --git a/libs/plugins/modifier.truncate.php b/libs/plugins/modifier.truncate.php
index 33e7e53a..80dcdb53 100644
--- a/libs/plugins/modifier.truncate.php
+++ b/libs/plugins/modifier.truncate.php
@@ -42,8 +42,8 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
}
- return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc .
- mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET);
+ return mb_substr($string, 0, intval($length / 2), Smarty::$_CHARSET) . $etc .
+ mb_substr($string, -intval($length / 2), $length, Smarty::$_CHARSET);
}
return $string;
}
@@ -56,7 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) {
return substr($string, 0, $length) . $etc;
}
- return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
+ return substr($string, 0, intval($length / 2)) . $etc . substr($string, -intval($length / 2));
}
return $string;
}