|
Posted by Oli Filth on 05/28/06 07:00
Norman Peelman said the following on 28/05/2006 03:45:
> "Chung Leong" <chernyshevsky@hotmail.com> wrote in message
> news:1148755585.431248.282160@j55g2000cwa.googlegroups.com...
>> Rik wrote:
>>> Let's say $text = "2 + 2 = " or " = 2 + 2"
>>>
>>> echo 2 + 2 . $text;
>>> echo $text . 2 + 2;
>>>
>>> It just makes sense to me....
>> Well, it didn't make sense to the other Rik ;-)
>>
> It makes sense because as soon as you try to ADD a number to a 'string'
> (or a 'string' to a 'string'), the strings are lost (counted as zero):
>
> echo 'A + B = ' . 'A' + 'B';
>
> will output zero (0)
> 'A + B = ' . 0 + 0 = 0
> 0 . 0 = 0
> 0 = 0
Actually, that's doing:
'A + B = ' . 'A' + 'B'
'A + B = A' + 'B'
0 + 0
0
(the . is evaluated first, due to left associativity.)
> echo 'A + B = ' . 'A' + 'B' + 100;
>
> will output 100 (0 + 100)
> 'A + B = ' . 0 + 0 + 100 = 100
> 0 . 0 + 100 = 100
> 0 + 100 = 100
> 100 = 100
Similarly for this one.
> It's
> not really about precidence at all as no math is done within quoted strings
> (literals).
It's *all* about precedence (and associativity, indirectly), and that's
the point Chung was making.
The fact that the examples all contain things like "A + B = " is
irrelevant, and just confusing things...
--
Oli
Navigation:
[Reply to this message]
|