|
Posted by Norman Peelman on 05/29/06 02:05
"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1148841404.688262.297960@i40g2000cwc.googlegroups.com...
> Norman Peelman wrote:
> > The bottom line is this... precedence can only 'guess' so much as to
what
> > you the programmer wants and it normally does a great job. But when you
> > start mixing two different functions ('.' and '+') it has to make
> > assumptions, and those assumptions are to work on what is immediately
known
> > and that is what is to the immediate left and right:
>
> I'm sorry but you're missing the entire point of the discussion. The
> point is that the ambiguity is illogical and should not exist. To use
> your terminology, apples are apples, oranges are oranges. Putting them
> all in one bin and then guess at what you've got is stupid.
>
So, what would you want to happen? Should the parser go through each
entire string looking for math equations first then string everything
together after. I'm thinking that the problem is probably the loose type
casting of the language. I'm thinking that under normal circumstances math
is not normally done within a string.
Normally: (oldskool, no mistake as to what is expected)
$sum = 7 + 7;
$str = 'sum = ';
echo $str , $sum;
outputs:
sum = 14
....so there you have it, no ambiguity. Ambiguity only comes into play when
programmers use tricky/bad programming practices because PHP will 'attempt'
to give them what they want. Ambiguity comes into play when new programmers
who haven't rtfm/googled/etc. rely on code snippets found here and there to
piece together something they barely understand to begin with. PHP is meant
to be learned easily (but not meant to teach programming knowledge/habits)
by allowing leeway in programming style. This leeway allows
experienced/advanced programmers to use the language to their advantage.
The bottom line is that '.' and '+' are/were not really meant to be used at
the same time as one works with strings and one works with mathematics. So
normally there would be no ambiguity. Type casting 'allows' it to be done so
that someone who has an understanding of what's going on can proceed without
having to use/write functions to convert strings and numbers back and forth.
If you want:
$a = 'If you multiply ' + 2 + 5 + 3 + ' by ' + 2 * 5 + ' you get ' + 10 *
10;
then you're asking too much of one operator let alone the parser.
---
Norm
Navigation:
[Reply to this message]
|