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... ?php $filter['flags'] = 0; if( $allow_fraction ) { $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION; } if( $allow_thousand ) {

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 http://en.wikipedia.org/wiki/Bitwise_operation#OR this makes much more sense to me now; as ive seen this technique

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 http://en.wikipedia.org/wiki/Bitwise_operation#OR this makes much more sense to me now; as ive seen this technique

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: ?php $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[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;

[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? ?php $flags = array(); if ($allow_fraction) { $flags[] = FILTER_FLAG_ALLOW_FRACTION; } if ($allow_thousand) { $flags[] = FILTER_FLAG_ALLOW_THOUSAND; } if ($allow_scientific) { $flags[] =

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? ?php $flags = array(); if ($allow_fraction) { $flags[] = FILTER_FLAG_ALLOW_FRACTION; } if ($allow_thousand) { $flags[] =

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? ?php $flags = array(); if ($allow_fraction) { $flags[] =

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? ?php $flags = array(); if

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: ?php $filter['flags'] = FALSE; if ($allow_fraction) { $filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_FRACTION; } if ($allow_thousand) { $filter['flags'] =

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 anyone think of a more

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éssel 14.13-kor Richard

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: ?php $filter['flags'] = FALSE; if ($allow_fraction) { $filter['flags'] = $filter['flags'] |

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... ?php $filter['flags'] = 0; if( $allow_fraction ) { $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION; } if( $allow_thousand ) { $filter['flags'] |= FILTER_FLAG_ALLOW_THOUSAND;

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... ?php $filter['flags'] = 0; if( $allow_fraction ) { $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION; } if(

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 I'd do

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

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... ?php $filter['flags'] = 0; if( $allow_fraction )

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? ?php $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[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

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 what was