ID:               19883
 Comment by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Bogus
 Bug Type:         Strings related
 Operating System: Windows NT
 PHP Version:      4.2.0
 New Comment:

ok, ok,
I understand, I also read carefully the docs,
I know there is 10000000 ways to avoid a syntax problem,

'.' operator have left associativity and that mean
that when the parser found a '.' it operate the
concatenation function with the left member first.
I talk about a very special case when the left member
is a decimal digit (maybe we meet a float ?) and there
is no digit on the right side :

is a float in the form 123. is a float ?
- yes because the dot say that it is a float (see IEEE ...)
- not really because there is no decimal part, only integer
  so it can be considered as a integer. (round integer)
- the php introduce '.' as an operator but it is in some
  way imcompatible with the '.' definition with floats.

so what is the good decision to make ?

only ask to a human reader what did he understand
when he see :

123.'km'

and

0x45.'km'
or 145.7.'km'

ask anyone why the first case is false and try
to explain that this is in the doc, that the '.' operator
have left associativity and that 123 is a very special
case. Syntax rules should avoid us to do 'meaning' errors
but i'm not sure that the decision to take 2. as a float
in this case is a good decision.

And ... that's only my opinion, sorry to hurt you ...
I'm programming script parser since more than 15 years
and sometime it is better to listen users than stopping
to the docs and technical difficulties...

have a nice day.


Previous Comments:
------------------------------------------------------------------------

[2002-10-13 12:09:03] [EMAIL PROTECTED]

THIS IS NOT A BUG!
Read the docs about operator precedence
(http://www.php.net/manual/en/language.operators.php#language.operators.precedence).
To avoid problems like these use parentheses ():
echo 'c='.($a*2).' ok';

------------------------------------------------------------------------

[2002-10-13 12:03:06] [EMAIL PROTECTED]

Yes, of course,
I was only thinking that the advantage of PHP over C
was that we can concatenate easily strings with
expressions and functions results when setting variable,
calling functions ...

this syntax allow to do :

something('a='.$a.' and f(a)*2 = '.f($a)*2.' ...');

instead of :
$str = 'a=';
$str .= $a;
$str .= ' and f(a)*2 = ';
$str .= f($a)*2;
$str .= ' ...';
something($str);

or :
$str = sprintf('a=%d and f(a)*2 = %d ...', $a, f($a)*2);
something($str);

I really think that if you allow this kind of concatenation
to avoid complex string composition, then the 'float'
problem is a bug, standard C does not allow dynamic
string concatenation but in C++ you can overload the '+'
operator and there is no confusion with the '.'

I know there is always a way to overcome the problem
in syntax, my report is only about something that
appear to me to be an error.

Julien.

------------------------------------------------------------------------

[2002-10-13 11:38:29] [EMAIL PROTECTED]

In that case, simply use

$i = 153;
echo $i*2
echo 'km';

or printf()...

------------------------------------------------------------------------

[2002-10-13 11:16:05] [EMAIL PROTECTED]

and when you want to concatenate with dynamic
calculated infos ?

$i = 153;
echo $i*2.'km';

------------------------------------------------------------------------

[2002-10-13 09:47:57] [EMAIL PROTECTED]

Why don't you just use '2km' instead of 2.'km' ?

Derick

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/19883

-- 
Edit this bug report at http://bugs.php.net/?id=19883&edit=1

Reply via email to