Bug #69091 [Opn->Csd]: assign by reference and math

[email protected] ("rstoll at tutteli dot ch")
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=69091&edit=1

 ID:                 69091
 User updated by:    rstoll at tutteli dot ch
 Reported by:        rstoll at tutteli dot ch
 Summary:            assign by reference and math
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            PHP Language Specification
 PHP Version:        5.6.6
 Block user comment: N
 Private report:     N

 New Comment:

ok, if this is really intentional. Not very intuitive but fair enough. IMO the precedence table in the doc should be updated (but this is covered by [2] as mentioned in your comment). Additionally, the spec should have a precedence table as well. But maybe it was left out on purpose. I will write to the standard list concerning this point.

Thanks for your quick answer.


Previous Comments:
------------------------------------------------------------------------
[2015-02-20 19:18:12] cmbecker69 at gmx dot de

The language specification further states[1]:

| assignment-expression must be an lvalue, a call to a function
| that returns a value byRef, or a new-expression (see comment below
| regarding this).

However, $a+1 is neither of these, so $a =& ($a + 1) is invalid;
therefore ($a =& $a) + 1 is tried and successfully parsed.

This issue is closely related to #68804[2], BTW.

[1] <https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#byref-assignment>
[2] <https://bugs.php.net/bug.php?id=68804>

------------------------------------------------------------------------
[2015-02-20 15:17:06] rstoll at tutteli dot ch

Description:
------------
assign by reference in conjunction with arithmetic does not result in a syntax error as expected. The test script shows two examples. The first one is correct according to the current implementation, but should result in a parser error IMO. The second results in a parser error (how it should be). 

It seems like the parser has a wrong precedence. I think the problem is this line in the grammar:
http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_language_parser.y#777

The langspec does not mention operator precedence explicitly (which should be added IMO) but implicitly the =& operator can be found in the section "Assignment Operator" (https://github.com/php/php-langspec/blob/b1e7a65fb9c985a8114322330468b77fb955cfae/spec/19-grammar.md#assignment-operators)
which is further below than +

Test script:
---------------
$a = &$a + 1;
$a = 1 + &$a;

Expected result:
----------------
parser error in both cases or the precedence explanation needs to be changed. 
Reading the spec I would assume the first line in the code above is equivalent to:
$a = (&$a + 1);
and not
($a = &$a) + 1;





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



--
Edit this bug report at https://bugs.php.net/bug.php?id=69091&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.