#28760 [Bgs]: Precedence of + - . incorrect in docs.
| From: | mgf@php.net | Date: | Mon, 05 Jul 2004 08:40:09 +0000 |
| Subject: | #28760 [Bgs]: Precedence of + - . incorrect in docs. | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969361666@lists.php.net to get a copy of this message | ||
ID: 28760
Updated by: mgf@php.net
Reported By: james at gogo dot co dot nz
Status: Bogus
Bug Type: Documentation problem
Operating System: Linux
PHP Version: 4.3.4
New Comment:
Actually, taking another look at this, although I think you'd have to
be unbelievably literal-minded to take the wrong interpretation that's
been taken here, the manual is, perhaps, a little less exact than it
could be.
The sentence at the top of the operator-precedence table that reads:
"The following table lists the precedence of operators with the
highest-precedence operators listed first."
could just be interpreted so that the single entry for "+ - ." is taken
to mean that "+" is of higher precedence than "-" is of higher
precedence than ".". The problem word here is "before" -- perhaps it
should read "above" (or something similar). Also, there's no reference
here to what the "Associativity" column might be about. So, all in all,
perhaps this sentence should be expanded slightly to something like:
"The following table lists the precedence of operators with the
highest-precedence operators listed at the top of the table. Operators
on the same line have equal precedence, in which case their
associativity decides which order to evaluate them in."
Cheers!
Mike
Previous Comments:
------------------------------------------------------------------------
[2004-06-13 14:59:50] derick@php.net
This is not a documentation problem at all, please don't close it as
that.
------------------------------------------------------------------------
[2004-06-13 04:52:54] curt@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
the output should really be:
-5
5
if operator precedence is equal, left to right associativity is used.
To obtain preferred precendence use ().
------------------------------------------------------------------------
[2004-06-13 01:37:28] james at gogo dot co dot nz
Description:
------------
In http://www.php.net/manual/en/language.operators.php
the relative
precedence of + - and . is listed as '+ - .' indicating that + and -
operations should happen before . operations.
However the code here shows that concatenation happens first.
Personally I would prefer that concatenation happened last as in the
docs as it would be much more sensible (you hardly ever want to use + -
on a result of a concatenation, but often want to use the result of a +
- in a concatenation), but that's obviously too big a change now.
Reproduce code:
---------------
echo 'Foo' . 5 - 5;
echo "\n";
echo 'Foo' . 5 + 5;
Expected result:
----------------
I expect to get the following
---
Foo0
Foo10
---
(+ and - happen first, then concatenation, as according to
documentation)
Actual result:
--------------
The result you get is
---
0
5
---
(. happens first, then the resulting string is evaluated as int
producing 0 which is combined with the next operator and value to
produce the result).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28760&edit=1