Req #63862 [Nab->Opn]: Passing by reference: func($a = $b);

From: Date: Wed, 09 Oct 2013 07:26:48 +0000
Subject: Req #63862 [Nab->Opn]: Passing by reference: func($a = $b);
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10459@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63862&edit=1 ID: 63862 Updated by: datibbaw@php.net Reported by: bobwei9 at hotmail dot com Summary: Passing by reference: func($a = $b); -Status: Not a bug +Status: Open Type: Feature/Change Request Package: Documentation problem Operating System: Mac OS X Mountain Lion PHP Version: master-Git-2012-12-27 (Git) Block user comment: N Private report: N New Comment: This behaviour is documented under the References section: http://www.php.net/manual/en/language.references.pass.php This is not going to change. Previous Comments: ------------------------------------------------------------------------ [2013-10-09 07:20:24] krakjoe@php.net This is expected behaviour, you cannot use an expression as a reference, you must assign the result of the expression to a variable and pass it by reference. ------------------------------------------------------------------------ [2013-01-05 10:35:17] bobwei9 at hotmail dot com Yeah, it is primarily not documented, but is there a reason why not to change behavior? I don't think that it'll introduce a BC break, because it makes today no sense to write such a code. (Throws E_STRICT error) I mean: if there is a $variable = on the beginning of an argument and the argument expects a reference, then evaluate first the part after the first =, assign the result to the $variable and pas this variable by reference. Or requires this minor change to be a rfc...? ------------------------------------------------------------------------ [2013-01-05 05:09:45] laruence@php.net $a = $b result a tmp value, not the left variable self. I wrote a simple explaination for this before, (however it's in chinese) http://www.laruence.com/2010/01/03/1225.html change to doc problem instead ------------------------------------------------------------------------ [2012-12-31 22:52:06] bobwei9 at hotmail dot com I know how it works now, but I don't know if it is intended (It isn't documented.) Then I wish that the first variable $a = $b = $c; is passed by array. ------------------------------------------------------------------------ [2012-12-31 22:06:57] mail+php at requinix dot net FYI: Expected behavior. The "value" of an assignment is just a value and not a reference to a variable, just like how "true?$a:$b" is the value of $a and not actually the variable $a. I don't think it would be so difficult to change that behavior but I'm afraid of the consequences it might have. There's also a more subtle change that would be required for your shorthand to work. Assignment currently propagates the right-most operand: $a=$b=$c is almost equivalent* to $b=$c;$a=$c; and not $b=$c;$a=$b; Unless that changes as well then sort($array=[3,1,2]) would try to sort the [3,1,2] and not $array. * $c is evaluated only once ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=63862 -- Edit this bug report at https://bugs.php.net/bug.php?id=63862&edit=1

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