smarty icon indicating copy to clipboard operation
smarty copied to clipboard

Deprecation warning in "is odd by 2" statement

Open m-ober opened this issue 2 years ago • 3 comments

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 avatar Mar 12 '23 20:03 m-ober

@m-ober which Smarty version and which PHP version are you using?

wisskid avatar Mar 17 '23 12:03 wisskid

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

m-ober avatar Mar 17 '23 13:03 m-ober

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}');

m-ober avatar Sep 15 '23 22:09 m-ober