ID:               49069
 Updated by:       j...@php.net
 Reported By:      weierophin...@php.net
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Ubuntu 9.04
 PHP Version:      5.3.0
 New Comment:

And this isn't even a bug but just how it's supposed to work. See also:
#43568 (and read comments by uw/johannes :)


Previous Comments:
------------------------------------------------------------------------

[2009-07-27 04:25:30] ras...@php.net

Note though that you only see this when you call it via
call_user_func().  Change your script to call it directly:

array_multisort($array1, $sort1a, $sort1b, $array2, $sort2a, $sort2b,
&$array3);

and you get your expected output and no warning.  This is more about
call_user_func() than about array_multisort() specifically.

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

[2009-07-27 03:52:24] weierophin...@php.net

Description:
------------
Prior to 5.3.0, array_multisort() expected no references; the last
array provided would be assumed to be a reference, and updated by the
function during processing.

Starting in 5.3.0, array_multisort() now expects all arguments to be
passed by reference, raising a warning if it detects any are passed by
copy. This also includes the various sort flags (which simply does not
make sense, since the SORT_* constants are typically passed directly).

In the reproduce code below, if you pass all arguments by reference,
you get the expected result. However, this is a BC break from previous
versions of PHP, as you were not required to pass by reference.

An additional BC break occurs with the results: if you ignore the
warning, the results returned differ from what was returned prior to 5.3
(this is shown below). You will only get the expected results if, again,
all arguments are passed by reference.

Reproduce code:
---------------
$array1 = array('foo', 'bar', 'baz');
$array2 = array('baz', 'bar', 'foo');
$array3 = array('Foo', 'Bar', 'Baz');
$sort1a  = SORT_ASC;
$sort1b  = SORT_STRING;
$sort2a  = SORT_ASC;
$sort2b  = SORT_REGULAR;

$args = array($array1, $sort1a, $sort1b, $array2, $sort2a, $sort2b,
&$array3);
call_user_func_array('array_multisort', $args);
var_export($array3);


Expected result:
----------------
array (
  0 => 'Bar',
  1 => 'Baz',
  2 => 'Foo',
)

Actual result:
--------------
Warning: Parameter 1 to array_multisort() expected to be a reference,
value given in /home/matthew/tmp/test.php on line 23
array (
  0 => 'Foo',
  1 => 'Bar',
  2 => 'Baz',
)


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


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

Reply via email to