Re: [SMARTY] Bit code
| From: | messju mohr | Date: | Sat, 29 Mar 2003 14:05:14 +0000 |
| Subject: | Re: [SMARTY] Bit code | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8984@lists.php.net to get a copy of this message | ||
On Sat, Mar 29, 2003 at 01:58:08PM +0000, messju mohr wrote:
> 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
actually it is not a bug. php does a bitwise-and if both operands are
strings. so '1' and '16' results in the string "1".chr(0) this leads
to
true for the "if".
HTH
messju
> (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
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Stockoptions: Die Geschäftsleitung behält sich vor, die Prügelstrafe
einzuführen.
Manfred Worm Schäfer