Re: [PHP] Need a more elegant way of bitwise ORing values

2007-06-17 Thread Nathan Nobbe
admittedly i had to read up quickly on the usage of a *binary pattern* where each bit in said* pattern* is used to represent the state of some boolean variable. wikipedia sufficed this makes much more sense to me now; as ive seen this technique b

Re: Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-17 Thread Nathan Nobbe
admittedly i had to read up quickly on the usage of a *binary pattern*where each bit in said *pattern* is used to represent the state of some boolean variable. wikipedia sufficed this makes much more sense to me now; as ive seen this technique b

Re: Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-17 Thread Robin Vickery
On 13/06/07, Richard Davey <[EMAIL PROTECTED]> wrote: Hi Robert, Wednesday, June 13, 2007, 3:15:39 PM, you wrote: > It's terribly verbose and inefficient... > $filter['flags'] = 0; > if( $allow_fraction ) > { > $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION; > } > if( $allow_thousand )

Re[7]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-16 Thread Richard Davey
Hi tedd, Saturday, June 16, 2007, 1:18:58 PM, you wrote: > How about? > switch (1) > { > case $allow_fraction: > $filter['flags'] = FILTER_FLAG_ALLOW_FRACTION; > break; > case $allow_thousand: > $filter['flags'] = FILTER_FLAG_ALLOW_THOUSAND; >

Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-16 Thread tedd
At 3:19 PM +0100 6/13/07, Richard Davey wrote: $filter['flags'] = 0; > if( $allow_fraction ) { > $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION; } > if( $allow_thousand ) { > $filter['flags'] |= FILTER_FLAG_ALLOW_THOUSAND; } > if( $allow_scientific ) { >

Re: Re[2]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Robert Cummings
On Thu, 2007-06-14 at 00:33 +0100, Richard Davey wrote: > Hi Richard, > > Wednesday, June 13, 2007, 6:44:55 PM, you wrote: > > >> if ($allow_fraction) > > > //Should we warn you that $allow_fraction is not actually defined?... > > Should I warn you that to save everyone's sanity I only posted w

Re[2]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Richard, Wednesday, June 13, 2007, 6:44:55 PM, you wrote: >> if ($allow_fraction) > //Should we warn you that $allow_fraction is not actually defined?... Should I warn you that to save everyone's sanity I only posted what was needed from the code? ;) $allow_fraction came from a function para

Re: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Lynch
On Wed, June 13, 2007 8:13 am, Richard Davey wrote: > Hi all, > > Can anyone think of a more elegant way of achieving the following? > > $flags = array(); $flags = 0; > > if ($allow_fraction) //Should we warn you that $allow_fraction is not actually defined?... //You don't have register_globals

RE: Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Ford, Mike
> From: Richard Davey [mailto:[EMAIL PROTECTED] > Sent: Wed 13/06/2007 15:19 > To: PHP List > > > Hi Robert, > > Wednesday, June 13, 2007, 3:15:39 PM, you wrote: > > > It's terribly verbose and inefficient... > > > > > $filter['flags'] = 0; > > > if( $allow_

Re: Re[8]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Robert Cummings
On Wed, 2007-06-13 at 15:59 +0100, Richard Davey wrote: > Hi Robert, > > Wednesday, June 13, 2007, 3:37:38 PM, you wrote: > > > Personally I hate constants (can't use non-scalar values so why get used > > ot them... also they're just another point for name collision) so if it > > were my own code

Re: Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Robert Cummings
On Wed, 2007-06-13 at 15:19 +0100, Richard Davey wrote: > Hi Robert, > > Wednesday, June 13, 2007, 3:15:39 PM, you wrote: > > > It's terribly verbose and inefficient... > > > > > $filter['flags'] = 0; > > > if( $allow_fraction ) > > { > > $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION; >

Re[8]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Robert, Wednesday, June 13, 2007, 3:37:38 PM, you wrote: > Personally I hate constants (can't use non-scalar values so why get used > ot them... also they're just another point for name collision) so if it > were my own code I'd do something more like the following: Sure, but the filter exten

Re[6]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Robert, Wednesday, June 13, 2007, 3:15:39 PM, you wrote: > It's terribly verbose and inefficient... > $filter['flags'] = 0; > if( $allow_fraction ) > { > $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION; > } > if( $allow_thousand ) > { > $filter['flags'] |= FILTER_FLAG_ALLOW_THOUSAND

Re: Re[4]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Robert Cummings
On Wed, 2007-06-13 at 15:05 +0100, Richard Davey wrote: > Hi Tijnema, > > Wednesday, June 13, 2007, 2:42:28 PM, you wrote: > > > Nice one, but you could also do it like this: > > > > $filter['flags'] = FALSE; > > > if ($allow_fraction) > > { > >$filter['flags'] = $filter['flags'] | FILTER_

Re[4]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Zoltán, Wednesday, June 13, 2007, 3:09:16 PM, you wrote: > 2007. 06. 13, szerda keltezéssel 15.42-kor Tijnema ezt írta: >> On 6/13/07, Richard Davey <[EMAIL PROTECTED]> wrote: >> > Hi Zoltán, >> > >> > Wednesday, June 13, 2007, 2:21:18 PM, you wrote: >> > >> > > 2007. 06. 13, szerda keltezésse

Re: Re[2]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Zoltán Németh
2007. 06. 13, szerda keltezéssel 15.42-kor Tijnema ezt írta: > On 6/13/07, Richard Davey <[EMAIL PROTECTED]> wrote: > > Hi Zoltán, > > > > Wednesday, June 13, 2007, 2:21:18 PM, you wrote: > > > > > 2007. 06. 13, szerda keltezéssel 14.13-kor Richard Davey ezt írta: > > >> Hi all, > > >> > > >> Can a

Re[4]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Tijnema, Wednesday, June 13, 2007, 2:42:28 PM, you wrote: > Nice one, but you could also do it like this: > $filter['flags'] = FALSE; > if ($allow_fraction) > { >$filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_FRACTION; > } > if ($allow_thousand) > { >$filter['flags'] = $fi

Re: Re[2]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Tijnema
On 6/13/07, Richard Davey <[EMAIL PROTECTED]> wrote: Hi Zoltán, Wednesday, June 13, 2007, 2:21:18 PM, you wrote: > 2007. 06. 13, szerda keltezéssel 14.13-kor Richard Davey ezt írta: >> Hi all, >> >> Can anyone think of a more elegant way of achieving the following? >> >> > $flags = array(); >>

Re[2]: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi Zoltán, Wednesday, June 13, 2007, 2:21:18 PM, you wrote: > 2007. 06. 13, szerda keltezéssel 14.13-kor Richard Davey ezt írta: >> Hi all, >> >> Can anyone think of a more elegant way of achieving the following? >> >> > $flags = array(); >> >> if ($allow_fraction) >> { >> $flags[] = FILTE

Re: [PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Zoltán Németh
2007. 06. 13, szerda keltezéssel 14.13-kor Richard Davey ezt írta: > Hi all, > > Can anyone think of a more elegant way of achieving the following? > > $flags = array(); > > if ($allow_fraction) > { > $flags[] = FILTER_FLAG_ALLOW_FRACTION; > } > > if ($allow_thousand) > { > $flags[] =

[PHP] Need a more elegant way of bitwise ORing values

2007-06-13 Thread Richard Davey
Hi all, Can anyone think of a more elegant way of achieving the following? 0) { $c = '$c = ' . implode('|', $flags) . ';'; eval($c); $filter['flags'] = $c; } ?> The code checks for 3 booleans ($allow_fraction, etc) and if true it adds the const to the $flags array. At the end each v