Doc #66772 [Opn]: Comma operator has insufficient documentation
| From: | cmbecker69 at gmx dot de | Date: | Sun, 06 Jul 2014 10:52:38 +0000 |
| Subject: | Doc #66772 [Opn]: Comma operator has insufficient documentation | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-11340@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
User updated by: cmbecker69 at gmx dot de
Reported by: cmbecker69 at gmx dot de
Summary: Comma operator has insufficient documentation
Status: Open
Type: Documentation Problem
Package: Documentation problem
Operating System: *
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
> 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.
Previous Comments:
------------------------------------------------------------------------
[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