#42674 [Opn]: missing error when assigning vars in reference arguments
| From: | jani@php.net | Date: | Tue, 18 Sep 2007 10:46:48 +0000 |
| Subject: | #42674 [Opn]: missing error when assigning vars in reference arguments | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17@lists.php.net to get a copy of this message | ||
ID: 42674
Updated by: jani@php.net
Reported By: Slig at free dot fr
Status: Open
-Bug Type: Variables related
+Bug Type: Documentation problem
Operating System: linux-64
PHP Version: 5CVS-2007-09-14 (snap)
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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