Re: Boolean type forced on string assignment inside if statement
| From: | Tim Streater | Date: | Wed, 02 Jan 2013 17:23:00 +0000 |
| Subject: | Re: Boolean type forced on string assignment inside if statement | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-319996@lists.php.net to get a copy of this message | ||
On 02 Jan 2013 at 16:05, Stephen <stephen-d@rogers.com> wrote:
> 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
OP may want to avoid doing something unusual which may confuse a casual reader.
--
Cheers -- Tim