|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62778 pre-increment operator produces rvalue rather than lvalue
Submitted: 2012-08-08 11:50 UTC Modified: -
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: dexen dot devries at gmail dot com Assigned:
Status: Open Package: Variables related
PHP Version: 5.4.6RC1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-08-08 11:50 UTC] dexen dot devries at gmail dot com
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;



$b =& ++$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)


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Aug 18 23:01:26 2019 UTC