Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation warning in "is odd by 2" statement #866

Open
m-ober opened this issue Mar 12, 2023 · 3 comments
Open

Deprecation warning in "is odd by 2" statement #866

m-ober opened this issue Mar 12, 2023 · 3 comments

Comments

@m-ober
Copy link

m-ober commented Mar 12, 2023

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

@wisskid
Copy link
Contributor

wisskid commented Mar 17, 2023

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

@m-ober
Copy link
Author

m-ober commented Mar 17, 2023

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
Copy link
Author

m-ober commented Sep 15, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants