From: dexen dot devries at gmail dot com
Operating system:
PHP version: 5.4.6RC1
Package: Variables related
Bug Type: Feature/Change Request
Bug description:pre-increment operator produces rvalue rather than lvalue
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 bug report at https://bugs.php.net/bug.php?id=62778&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62778&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62778&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=62778&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62778&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=62778&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62778&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=62778&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=62778&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=62778&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=62778&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=62778&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=62778&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=62778&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62778&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=62778&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62778&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=62778&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=62778&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=62778&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=62778&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=62778&r=mysqlcfg