Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-04 Thread tamouse mailing lists
On Fri, Jan 4, 2013 at 1:56 AM, Sebastian Krebs krebs@gmail.com wrote: 2013/1/4 tamouse mailing lists tamouse.li...@gmail.com Bit operators are not comparing values, they're COMBINING values. Technically spoken they're comparing bits, whereas boolean operators does the same, but treaten

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-04 Thread Sebastian Krebs
2013/1/4 tamouse mailing lists tamouse.li...@gmail.com On Fri, Jan 4, 2013 at 1:56 AM, Sebastian Krebs krebs@gmail.com wrote: 2013/1/4 tamouse mailing lists tamouse.li...@gmail.com Bit operators are not comparing values, they're COMBINING values. Technically spoken they're comparing

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-04 Thread tamouse mailing lists
On Fri, Jan 4, 2013 at 4:25 PM, Sebastian Krebs krebs@gmail.com wrote: 2013/1/4 tamouse mailing lists tamouse.li...@gmail.com On Fri, Jan 4, 2013 at 1:56 AM, Sebastian Krebs krebs@gmail.com wrote: 2013/1/4 tamouse mailing lists tamouse.li...@gmail.com Bit operators are not

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Jim Giner
On 1/2/2013 2:02 PM, Marc Guay wrote: Something else that's happening with this, which makes it a Bad Idea (tm) is that when the operator is or, as it is in my real life scenerio, the 2nd variable occasionally doesn't get populated if the first one returns true. if ($a = foo || $b = bar){

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Geoff Shang
On Thu, 3 Jan 2013, Jim Giner wrote: The only time I use a single '=' symbol in an if statement is when I forget to use two of them! Must be my old school, old languages habits but this style of programming reminds me of the days when we used to pack empty spaces in assembler code with

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread John Iliffe
On Thursday 03 January 2013 10:26:39 Jim Giner wrote: On 1/2/2013 2:02 PM, Marc Guay wrote: Something else that's happening with this, which makes it a Bad Idea (tm) is that when the operator is or, as it is in my real life scenerio, the 2nd variable occasionally doesn't get populated if

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Marc Guay
First, did the original poster realize that he was assigning a value to the variable $a in the 'if' statement? Hello, Yes, I did, and if you read my responses you can see that I came to the realisations you describe. I don't think that anyone suggested there was a bug. $a is true (ie it is

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread John Iliffe
On Thursday 03 January 2013 11:33:22 Marc Guay wrote: First, did the original poster realize that he was assigning a value to the variable $a in the 'if' statement? Hello, Yes, I did, and if you read my responses you can see that I came to the realisations you describe. I don't think

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread David OBrien
On Thu, Jan 3, 2013 at 11:49 AM, Marc Guay marc.g...@gmail.com wrote: Hi John, I just ran this: if (($a = foo) || ($b = bar)){ echo $a.br /.$b; } and it only spat out foo so I'm guessing things have changed. :) Marc -- PHP General Mailing List (http://www.php.net/) To

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Tedd Sperling
On Jan 3, 2013, at 11:49 AM, Marc Guay marc.g...@gmail.com wrote: I just ran this: if (($a = foo) || ($b = bar)){ echo $a.br /.$b; } and it only spat out foo so I'm guessing things have changed. :) Marc Marc et al: I joined late into this conversation, so I may be missing the

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Marc Guay
Hi Tedd, A little searching enlightened me to the fact that in other languages, a single | or operator will cancel the short-circuiting so all of the evaluations are done before proceeding. However, they don't seem to exist in PHP so in your example it behaves the same as ||...?

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Tedd Sperling
On Jan 3, 2013, at 12:09 PM, David OBrien dgobr...@gmail.com wrote: From what I understood about || is once it sees a true the whole statement is regarded as true so nothing else following matters so PHP ignores everything in the conditional after it evaluates as true... and once it sees a

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Jim Lucas
On 01/03/2013 09:25 AM, Marc Guay wrote: Hi Tedd, A little searching enlightened me to the fact that in other languages, a single | or operator will cancel the short-circuiting so all of the evaluations are done before proceeding. However, they don't seem to exist in PHP so in your example it

Fwd: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Marc Guay
/language.operators.bitwise.php -- Forwarded message -- From: Volmar Machado qi.vol...@gmail.com Date: 3 January 2013 12:42 Subject: Re: [PHP] Boolean type forced on string assignment inside if statement To: Marc Guay marc.g...@gmail.com My results in a simple test: ?php $a = true; $b

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Volmar Machado
-numbers). http://php.net/manual/en/language.operators.bitwise.php -- Forwarded message -- From: Volmar Machado qi.vol...@gmail.com Date: 3 January 2013 12:42 Subject: Re: [PHP] Boolean type forced on string assignment inside if statement To: Marc Guay marc.g...@gmail.com My

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Andreas Perstinger
Volmar Machado qi.vol...@gmail.com wrote: When the one of the operators were 2, the cases with returns 2 otherwise returns 0 (Or 1 when any operator is 1). And if the operators are 1 and 2, return 0 too. Its curious for me. is the bitwise and operator. You have to look at the binary

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Volmar Machado
Based on what I learned. I create this simple sample that can occurs in a real world application. This simulate a system that needs to send a mail when a flag ($mail) is true, the system need to check if the category is passed with the flag to know the type of mail to send. Here is the results.

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Jim Lucas
On 01/03/2013 11:43 AM, Andreas Perstinger wrote: is the bitwise and operator. So is a single pipe. http://php.net/manual/en/language.operators.bitwise.php -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe,

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-03 Thread Sebastian Krebs
2013/1/4 tamouse mailing lists tamouse.li...@gmail.com Bit operators and | are NOT and should NEVER be confused with Logical operators and ||: ?php /** * Bit operators in PHP */ $format = Decimal: %2d Binary: %4b\n; $a = 4; $b = 6; echo Variable \$a:\n; printf($format, $a,

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-02 Thread Stephen
On 13-01-02 10:53 AM, Marc Guay wrote: Hi folks, if ($a = foo $b = bar){ echo $a.br /.$b; } Returns: 1 bar I expect: foo bar Is this documented? takes precedence over = http://php.net/manual/en/language.operators.precedence.php You may want to use brackets -- Stephen -- PHP

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-02 Thread Jim Lucas
On 01/02/2013 07:53 AM, Marc Guay wrote: Hi folks, if ($a = foo $b = bar){ echo $a.br /.$b; } Returns: 1 bar I expect: foo bar Is this documented? Marc Why would you do this. I cannot envision a time or condition that would require such a test. Can you please explain why you

Re: [PHP] Boolean type forced on string assignment inside if statement

2013-01-02 Thread Jim Lucas
On 01/02/2013 10:21 AM, Marc Guay wrote: Won't this type of condition/test always return true? I simplified the example. In my real life case the foo and bar are variables which can be empty strings, and if they both are not, I would like to display them. Marc Then why not use empty()?