|
Posted by Rik G. on 05/27/06 15:39
"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:de52b$447846ce$8259c69c$22611@news1.tudelft.nl...
[Snip]
> Not only precedence, type juggling also plays a major part here.
> Detailed:
>
> >> echo "2 + 2 = " . 2+2; // This will print 4
>
> 1. The string "2 + 2 = " becomes "2 + 2 = 2" (indeed precedence).
> 2. Trying to add a number to this string casts it to 2 (the first number),
> and adds 2, so gives 4.
>
> >> echo "2 + 2 = " , 2+2; // This will print 2 + 2 = 4
>
> The string "2 + 2 = " gets echoed seperately from the integer resulting
from
> adding 2+2
>
> >> echo "test " . 2+2; // This will print 2
>
> 1. The string "test " becomes "test 2".
> 2. Trying to add the number 2 to "test 2" casts the string to an integer
> (0), and adding 2 gives indeed 2
>
> Variable variables, without strict type, are a blessing in some cases, in
> others it's immensely irritating. You just have to keep an eye on it :-).
OK, it's clear now (but still butt ugly).
Thanks for the explanation.
R.
Navigation:
[Reply to this message]
|