|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jonathan2014 Smarty n00b
Joined: 15 Feb 2016 Posts: 3
|
Posted: Mon Feb 15, 2016 1:49 pm Post subject: I think there is a bug in version 3.1.29 of smarty |
|
|
Platform: Centos 7
PHP: PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
smarty: 3.1.29
cgi:
<?php
require_once('classes/SmartySetup.class.php');
$smarty = new SmartySetup();
$smarty->assign('test', '2079');
$smarty->display('test.tpl');
?>
tpl:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
{if $test & 0x4000}hello{else}world{/if}
</body>
</html>
result:
This html shoud show string "world", but really show string "hello". why? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Feb 15, 2016 5:49 pm Post subject: |
|
|
You're doing bitwise operation on strings.
The result is undefined. |
|
Back to top |
|
jonathan2014 Smarty n00b
Joined: 15 Feb 2016 Posts: 3
|
Posted: Tue Feb 16, 2016 12:16 am Post subject: |
|
|
The above test running in version 2.0 of smarty is correct.
thanks
Last edited by jonathan2014 on Tue Feb 16, 2016 12:59 am; edited 1 time in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Feb 16, 2016 12:30 am Post subject: |
|
|
There's no "correct" results. Whatever you are getting is what you are getting.
If you want predictable results, use numbers instead.
Code: | <?php
require_once 'smarty-config.php';
$smarty->assign('test', 2079);
$smarty->display(__FILE__);
__HALT_COMPILER();
?>{if $test & 16384}hello{else}world{/if} |
|
|
Back to top |
|
jonathan2014 Smarty n00b
Joined: 15 Feb 2016 Posts: 3
|
Posted: Tue Feb 16, 2016 1:12 am Post subject: |
|
|
<?php
require_once 'smarty-config.php';
echo('2079', 0x4000); // correct
$smarty->assign('test0', '2079');
$smarty->assign('test1', 2079);
$smarty->display(__FILE__);
__HALT_COMPILER();
?>{if $test0 & 16384}hello{else}world{/if} // correct
{if $test0 & 0x4000}hello{else}world{/if} // error
{if $test1 & 0x4000}hello{else}world{/if} // correct
{if $test1 & 16384}hello{else}world{/if} // correct |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|