diff --git a/changelog/count.md b/changelog/count.md new file mode 100644 index 000000000..36a3099e3 --- /dev/null +++ b/changelog/count.md @@ -0,0 +1 @@ +- Fixed that using `count()` would trigger a deprecation notice. [#813](https://github.com/smarty-php/smarty/issues/813) \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 8ff3e0521..03797f7f8 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -658,7 +658,7 @@ public function compilePHPFunctionCall($name, $parameter) if ( !$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name) && !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name]) - && !in_array($name, ['time', 'join', 'is_array', 'in_array']) + && !in_array($name, ['time', 'join', 'is_array', 'in_array', 'count']) ) { trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' . 'removed in a future release. Use Smarty::registerPlugin to explicitly register ' . diff --git a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php index 9a3f63191..2c0ee95c8 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php @@ -247,6 +247,7 @@ public function testDeprecationNoticesForSmarty5($strTemplateSource, $expected = $this->smarty->assign('f', 3.14); $errorMessage = ''; + $output = ''; try { $output = $this->smarty->fetch('string:' . $strTemplateSource); @@ -282,6 +283,7 @@ public function dataDeprecationNoticesForSmarty5() ['{$a|substr:-1}', 'a', false], ['{$f|substr:-1}', '4', false], ['{$ar|count}', '2', false], + ['{count($ar)}', '2', false], ['{foreach "."|explode:$f as $n}{$n}{/foreach}', '314', false], ['{"-"|implode:$ar}', '1-2', false], ['{"-"|join:$ar}', '1-2', false],