Doc->Bug #66772 [Opn]: Comma operator does not behave as operator
| From: | yohgaki@php.net | Date: | Mon, 07 Jul 2014 05:38:17 +0000 |
| Subject: | Doc->Bug #66772 [Opn]: Comma operator does not behave as operator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186495@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66772&edit=1
ID: 66772
Updated by: yohgaki@php.net
Reported by: cmbecker69 at gmx dot de
-Summary: Comma operator has insufficient documentation
+Summary: Comma operator does not behave as operator
Status: Open
-Type: Documentation Problem
+Type: Bug
-Package: Documentation problem
+Package: Scripting Engine problem
Operating System: *
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Reasonable discussion.
Since this is documented for a long time, it may be good to categorize as engine issue.
Previous Comments:
------------------------------------------------------------------------
[2014-07-06 10:52:38] cmbecker69 at gmx dot de
> I think ',' is used to divide expressions just like C/C++,
> isn't?
It doesn't seem to be in the general case. For instance:
$a = (1, 2); // => syntax error, unexpected ','
Furthermore in C the comma operator doesn't simply divide
expressions, but is defined to evaluate the first operand
discarding the result, and than to evaluate the second operand
"returning" its result.
> echo 1,2,3,4;
This is possible due to the special grammar rule echo_expr_list.
> I'm not sure what do you mean by "the operator precedence table
> seems to be in error."
The *only* case where the comma can be used as *operator* seems to
be inside for_expr. However, the documentation states the comma
operator has *many* uses.
------------------------------------------------------------------------
[2014-07-06 02:52:11] yohgaki@php.net
I think ',' is used to divide expressions just like C/C++, isn't? Therefore,
echo 1,2,3,4;
as well as
$i=0;
echo ++$i, ++$i, ++$i;
works.
http://en.cppreference.com/w/cpp/language/operator_precedence
http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm
I'm not sure what do you mean by "the operator precedence table seems to be in
error."
------------------------------------------------------------------------
[2014-02-25 20:35:18] cmbecker69 at gmx dot de
Description:
------------
The section "Operator Precedence"[1] lists all operators and gives
a link to the manual section where they are described; for the
comma operator it only says "many uses". It seems to be
appropriate to list these many uses in an own section.
OTOH, from what I can tell from Zend/zend_language_parser.y[2] the
only actual place where the comma is used as operator (opposed to
a list delimiter) is inside for_expr. This usage is explained in
the "for" section[3]. If this is indeed the only use, the operator
precendence table seems to be in error.
[1] <http://www.php.net/manual/en/language.operators.precedence.php>
[2] <http://lxr.php.net/xref/PHP_5_5/Zend/zend_language_parser.y>
[3] <http://www.php.net/manual/en/control-structures.for.php>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66772&edit=1