Bug #69091 [Com]: assign by reference and math
[email protected] ("cmbecker69 at gmx dot de")
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=69091&edit=1 ID: 69091 Comment by: cmbecker69 at gmx dot de Reported by: rstoll at tutteli dot ch Summary: assign by reference and math Status: Open Type: Bug Package: PHP Language Specification PHP Version: 5.6.6 Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [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