Fixed that using count() would trigger a deprecation notice.

This commit is contained in:
Simon Wisselink
2024-08-14 00:43:41 +02:00
parent 9fc96a13db
commit ad364d3138
3 changed files with 4 additions and 1 deletions

1
changelog/count.md Normal file
View File

@ -0,0 +1 @@
- Fixed that using `count()` would trigger a deprecation notice. [#813](https://github.com/smarty-php/smarty/issues/813)

View File

@ -658,7 +658,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
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 ' .

View File

@ -247,6 +247,7 @@ class PhpFunctionTest extends PHPUnit_Smarty
$this->smarty->assign('f', 3.14);
$errorMessage = '';
$output = '';
try {
$output = $this->smarty->fetch('string:' . $strTemplateSource);
@ -282,6 +283,7 @@ class PhpFunctionTest extends PHPUnit_Smarty
['{$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],