Re: [SMARTY] Bit code

From: Date: Sat, 29 Mar 2003 14:13:14 +0000
Subject: Re: [SMARTY] Bit code
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8985@lists.php.net to get a copy of this message
putting (int) in front fixed it However the wierd thing is, thats not the real code, The real code loops through an array with 8 values and the problem only happens on a couple of the 8 spots, But the information is pulled the same way so all the variables are exactly the same. {section name=feature loop=$domain_features} <td class=noborder><input {if $domains.features & (int)$domain_features[feature].bitvalue} CHECKED {/if} class=buttons type=checkbox name=domainfeatures[] value={$domain_features[feature].bitvalue} {$readonly}>{$doma {if $smarty.section.feature.iteration is div by 8} </tr><tr> {/if} {/section} Now the way your explaining it this without the (int) all of them should of been checked, not just a couple of them. Results without the int have bitfields 1 , 16, 32, 128 checked when domain.features = 1 On Sat, 2003-03-29 at 08:05, messju mohr wrote: > 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

« previous php.smarty.general (#8985) next »