Skip to content

Commit 2adb880

Browse files
authoredAug 14, 2024
Fixed that using count() would trigger a deprecation notice. (#1054)

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed
 

‎changelog/count.md

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

‎libs/sysplugins/smarty_internal_templatecompilerbase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ public function compilePHPFunctionCall($name, $parameter)
658658
if (
659659
!$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name)
660660
&& !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])
661-
&& !in_array($name, ['time', 'join', 'is_array', 'in_array'])
661+
&& !in_array($name, ['time', 'join', 'is_array', 'in_array', 'count'])
662662
) {
663663
trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' .
664664
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .

‎tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public function testDeprecationNoticesForSmarty5($strTemplateSource, $expected =
247247
$this->smarty->assign('f', 3.14);
248248

249249
$errorMessage = '';
250+
$output = '';
250251

251252
try {
252253
$output = $this->smarty->fetch('string:' . $strTemplateSource);
@@ -282,6 +283,7 @@ public function dataDeprecationNoticesForSmarty5()
282283
['{$a|substr:-1}', 'a', false],
283284
['{$f|substr:-1}', '4', false],
284285
['{$ar|count}', '2', false],
286+
['{count($ar)}', '2', false],
285287
['{foreach "."|explode:$f as $n}{$n}{/foreach}', '314', false],
286288
['{"-"|implode:$ar}', '1-2', false],
287289
['{"-"|join:$ar}', '1-2', false],

0 commit comments

Comments
 (0)
Please sign in to comment.