Re: [SMARTY] Bit code
| From: | messju mohr | Date: | Sat, 29 Mar 2003 13:58:08 +0000 |
| Subject: | Re: [SMARTY] Bit code | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8983@lists.php.net to get a copy of this message | ||
On Sat, Mar 29, 2003 at 07:38:29AM -0600, Richard Thomas wrote:
> Having some problems creating dynamic checkboxes
>
>
> Ok, the following code should produce the same results, Nothing.. Value
> wise they are the exact same thing.. However if you run the code you
> will see "First" shows up and not second..
>
>
> {assign var="bitvalue" value='1'}
> {assign var="item" value='16'}
> {if $bitvalue & $item} First{/if}
> {if $bitvalue & 16} Second{/if}
i think the bug is in the automatic type handling of php. 16 is an int
while $item is a string (smarty treats every scalar value as a string
in the first place).
example:
printf("%d\n", '16' & '1'); // says "1" wrong
printf("%d\n", 16 & 1); // says "0" good
do:
{if (int)$bitvalue & (int)$item} First{/if}
{if (int)$bitvalue & 16} Second{/if}
and it works as expected.
greetings
messju