|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-09-14 17:48 UTC] Slig at free dot fr
Description:
------------
I know it has already be discused in #35995.
I do not really agree with that feature (it's accepted by other languages like C, and after assignment it's a variable which is passed to the function), but if this syntax is forbidden then it should make an error, else it is really difficult to fix it in old programs.
Also, because until 5.1.1 it worked like some of us expected, would be nice to add some warning about it in the documentation.
Reproduce code:
---------------
<?php
function myFunc(&$var1) {
$var1 = 'set in function';
}
$var2 = 'set before function';
myFunc($var2 = 'set in function call');
var_dump($var2);
?>
Expected result:
----------------
Fatal error: Cannot pass parameter 1 by reference in xxxx at line nn
Actual result:
--------------
No error, but the function get in $var1 the assigned value, and after the call $var2 get the assign value too (so not changed by the function)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 06:00:01 2025 UTC |
Ok, i didn't noticed it, thx :) Anyway, why "MyFunc($var2 = 'set in function call');" need E_STRICT, while "MyFunc('set in function call');" make "Fatal error: Only variables should be passed by reference in" without E_STRICT ? would be better to have both at the same error_reporting level, isn't it ? Btw, it would be good to have it warned in the documentation, probably in the part "III. Language Reference -> 21. References Explained -> Passing by Reference"