Req #62778 [Fbk->NoF]: pre-increment operator produces rvalue rather than lvalue
| From: | php-bugs at lists dot php dot net | Date: | Sun, 01 Sep 2019 04:22:08 +0000 |
| Subject: | Req #62778 [Fbk->NoF]: pre-increment operator produces rvalue rather than lvalue | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222514@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62778&edit=1
ID: 62778
Updated by: php-bugs@lists.php.net
Reported by: dexen dot devries at gmail dot com
Summary: pre-increment operator produces rvalue rather than
lvalue
-Status: Feedback
+Status: No Feedback
Type: Feature/Change Request
Package: Variables related
PHP Version: 5.4.6RC1
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2019-08-21 13:20:28] nikic@php.net
Is there any motivation for allowing this? PHP is pretty consistent about not returning references
from assignment-like operations -- the only one that does so is the proper by-reference assignment
(=&). I don't see any reason why we would want to change this.
------------------------------------------------------------------------
[2012-08-08 11:50:17] dexen dot devries at gmail dot com
Description:
------------
Result of pre-increment (also pre-decrement) operator is a value (
rvalue') rather than a
reference to variable (lvalue'). This prevents assigning result of the operator to
reference, or passing it by reference.
There is no apparent reason for such limitation; the operator only applies to variables (never to
other expressions), and PHP core supports references.
The requested behavior is similar to C++ (result of pre-increment operator is reference); the
current behavior mimics C (result of pre-increment operator is an rvalue).
Test script:
---------------
$a = 0;
$b = 0;
$c = 0;
function foo(&$v) {
$v = $v + 1;
}
++$a;
foo($a);
var_dump($a);
foo(++$b);
var_dump($b);
$b =& ++$c;
var_dump($c);
Expected result:
----------------
$a === 2
$b === 2
$c === 1
Actual result:
--------------
$a === 2
Strict Standards: Only variables should be passed by reference
$b === 1
PHP Parse error: syntax error, unexpected '++' (T_INC)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62778&edit=1