Edit report at https://bugs.php.net/bug.php?id=63862&edit=1

 ID:                 63862
 Comment by:         mail+php at requinix dot net
 Reported by:        bobwei9 at hotmail dot com
 Summary:            Passing by reference: func($a = $b);
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine 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:

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


Previous Comments:
------------------------------------------------------------------------
[2012-12-27 16:57:06] bobwei9 at hotmail dot com

Description:
------------
I don't know if this should be considered as a bug or as expected behaviour (=> 
feature request).

When passing an assignment to a function which expects a variable as reference 
like sort(), then an E_STRICT message is issued and nothing has changed.
What I want, is that a code like "sort($a = $b);" is executed in the same way 
as "$a = $b; sort($a);".

This could help to reduce the number of little, unnecessary lines.

Test script:
---------------
php -r 'sort($array = [3,1,2]); var_dump($array);'

Expected result:
----------------
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}


Actual result:
--------------
Strict Standards:  Only variables should be passed by reference in Command line 
code on line 1
array(3) {
  [0]=>
  int(3)
  [1]=>
  int(1)
  [2]=>
  int(2)
}



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63862&edit=1

Reply via email to