summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorMark Fettig <fettigms@gmail.com>2022-09-09 16:39:24 -0400
committerGitHub <noreply@github.com>2022-09-09 22:39:24 +0200
commit1bc7c722a39598bdbbd273f5d9d6b61764bb193a (patch)
treecba504935490b890efcec5a84578ac3fb9c9d7d6 /libs
parent02968a82b5f23ee4a16c1cbb121d5b9df5d5ce9d (diff)
downloadsmarty-1bc7c722a39598bdbbd273f5d9d6b61764bb193a.tar.gz
smarty-1bc7c722a39598bdbbd273f5d9d6b61764bb193a.tar.bz2
smarty-1bc7c722a39598bdbbd273f5d9d6b61764bb193a.zip
address PHP 8.1 'explode', 'number_format', and 'replace' deprecations (#755)
Diffstat (limited to 'libs')
-rw-r--r--libs/plugins/modifier.explode.php25
-rw-r--r--libs/plugins/modifier.number_format.php26
-rw-r--r--libs/plugins/shared.mb_str_replace.php2
3 files changed, 52 insertions, 1 deletions
diff --git a/libs/plugins/modifier.explode.php b/libs/plugins/modifier.explode.php
new file mode 100644
index 00000000..5186fde3
--- /dev/null
+++ b/libs/plugins/modifier.explode.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Smarty plugin
+ *
+ * @package Smarty
+ * @subpackage PluginsModifier
+ */
+
+/**
+ * Smarty explode modifier plugin
+ * Type: modifier
+ * Name: explode
+ * Purpose: split a string by a string
+ *
+ * @param string $separator
+ * @param string $string
+ * @param int|null $limit
+ *
+ * @return array
+ */
+function smarty_modifier_explode($separator, $string, ?int $limit = null)
+{
+ // provide $string default to prevent deprecation errors in PHP >=8.1
+ return explode($separator, $string ?? '', $limit ?? PHP_INT_MAX);
+}
diff --git a/libs/plugins/modifier.number_format.php b/libs/plugins/modifier.number_format.php
new file mode 100644
index 00000000..8c612601
--- /dev/null
+++ b/libs/plugins/modifier.number_format.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Smarty plugin
+ *
+ * @package Smarty
+ * @subpackage PluginsModifier
+ */
+
+/**
+ * Smarty number_format modifier plugin
+ * Type: modifier
+ * Name: number_format
+ * Purpose: Format a number with grouped thousands
+ *
+ * @param float|null $num
+ * @param int $decimals
+ * @param string|null $decimal_separator
+ * @param string|null $thousands_separator
+ *
+ * @return string
+ */
+function smarty_modifier_number_format(?float $num, int $decimals = 0, ?string $decimal_separator = ".", ?string $thousands_separator = ",")
+{
+ // provide $num default to prevent deprecation errors in PHP >=8.1
+ return number_format($num ?? 0.0, $decimals, $decimal_separator, $thousands_separator);
+}
diff --git a/libs/plugins/shared.mb_str_replace.php b/libs/plugins/shared.mb_str_replace.php
index c6079c12..7e85f7aa 100644
--- a/libs/plugins/shared.mb_str_replace.php
+++ b/libs/plugins/shared.mb_str_replace.php
@@ -62,7 +62,7 @@ if (!function_exists('smarty_mb_str_replace')) {
$replace = mb_convert_encoding($replace, $current_charset, Smarty::$_CHARSET);
}
- $parts = mb_split(preg_quote($search), $subject) ?: array();
+ $parts = mb_split(preg_quote($search), $subject ?? "") ?: array();
// If original regex encoding was not unicode...
if(!$reg_is_unicode) {
// ...restore original regex encoding to avoid breaking the system.