|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-08-21 13:20 UTC] nikic@php.net
-Status: Open
+Status: Feedback
[2019-08-21 13:20 UTC] nikic@php.net
[2019-09-01 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
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)