|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-10-09 20:58 UTC] tomas_matousek at hotmail dot com
Description:
------------
Let's have a function with a parameter passsed by reference.
function f(&$x) { }
Now, call this function as follows:
f($a = $b = $c);
This will sometimes fail sometimes not depending on whether any of the variables $a, $b, $c has previously been used with =& operator. In a such case, the call succeeds with $a being aliased to $x. Otherwise, fatal error occures: "Only variables can be passed by reference".
this code works:
$b =& $z;
f($a = $b = $c);
this code doesn't:
f($a = $b = $c);
So the "correctness" of the code depends on whether there exists an alias of one of the variable. That's weird, isn't it?
Reproduce code:
---------------
$b =& $z;
f($a = $b = $c);
f($u = $v = $w);
Expected result:
----------------
OK.
OK.
- or -
Error.
Error.
Actual result:
--------------
OK.
Error.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 17:00:01 2025 UTC |
Well, the versino in CVS doesn't report an error, however it passes by value instead which is imho also incorrect. Example: function f(&$x) { $x = 10; } $a = $b = $c = $d = $u = $v = $w = 1; $b =& $z; f($a = $b = $c); var_dump($a,$b,$c); f($u = $v = $w); var_dump($u,$v,$w); -------- prints: int(10) int(1) int(1) int(1) int(1) int(1) It should print int(10) int(1) int(1) int(10) int(1) int(1)