#42674 [Opn->Bgs]: missing error when assigning vars in reference arguments

From: Date: Wed, 21 Nov 2007 16:34:38 +0000
Subject: #42674 [Opn->Bgs]: missing error when assigning vars in reference arguments
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-244@lists.php.net to get a copy of this message
ID: 42674 Updated by: vrana@php.net Reported By: Slig at free dot fr -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: linux-64 PHP Version: 5CVS-2007-09-14 (snap) New Comment: There is a list of values passable be reference in References Explained with the description of behavior of other values: "Any other expression should not be passed by reference, as the result is undefined." Previous Comments: ------------------------------------------------------------------------ [2007-09-19 08:16:04] Slig at free dot fr 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" ------------------------------------------------------------------------ [2007-09-18 10:46:48] jani@php.net You do get an error, with E_STRICT enabled: Strict Standards: Only variables should be passed by reference in /home/jani/t.php on line 7 Reclassified as documentation issue. ------------------------------------------------------------------------ [2007-09-14 17:48:34] 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) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42674&edit=1

« previous php.doc.bugs (#244) next »