smarty
smarty copied to clipboard
Deprecation warning in "is odd by 2" statement
This statement:
{if $r@total is odd by 2}
is compiled to:
if ((1 & $_smarty_tpl->tpl_vars['r']->total / 2)) {
which produces the warning:
E_DEPRECATED: Implicit conversion from float 7.5 to int loses precision
@m-ober which Smarty version and which PHP version are you using?
PHP 8.2.1 and Smarty 4.3.0.
You can also reproduce this using {if 17 is odd by 2}{/if}.
Looks like this deprecation was introduced with PHP 8.1: https://php.watch/versions/8.1/deprecate-implicit-conversion-incompatible-float-string.
Demo of the compiled code: https://onlinephp.io/c/7a34d
I can still reproduce this with Smarty 5.0.0-rc1 / dev-master. MWE:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'vendor/autoload.php';
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->display('string:{if 17 is odd by 2}{/if}');