Bug #66772 [Opn]: Comma operator does not behave as operator

From: Date: Mon, 07 Jul 2014 11:44:07 +0000
Subject: Bug #66772 [Opn]: Comma operator does not behave as operator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186500@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 does not behave as operator
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

> Since this is documented for a long time, it may be good to
> categorize as engine issue.

Please note, that I do not suggest to implement a universal comma
operator as in C/C++. Actually, I believe that it is not necessary
and doesn't have real benefits (at least in PHP).

IMHO it would be sufficient to document the comma operator more
clearly, or perhaps, to not categorize it as *operator* at all
(Java does not have a comma operator[1], but similar uses of the
comma as in PHP).

[1]
<http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.27-120>


Previous Comments:
------------------------------------------------------------------------
[2014-07-07 05:38:16] yohgaki@php.net

Reasonable discussion.

Since this is documented for a long time, it may be good to categorize as engine issue.

------------------------------------------------------------------------
[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


Thread (1 message)

  • cmbecker69 at gmx dot de
  • Unknown Message
    • cmbecker69 at gmx dot de
« previous php.bugs (#186500) next »