ID:               50421
 Updated by:       [email protected]
 Reported By:      v1d4l0k4 at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Ubuntu 9.10
 PHP Version:      5.2.11
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php




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

[2009-12-09 04:09:02] v1d4l0k4 at gmail dot com

Description:
------------
PHP 5.2.10 introduced a controversial BC break in array_rand() function
that doesn't sort array values when the $num_req param is equal to array
count.

This was the most incomprehensive change I've seen in the PHP
development so far.

If I have a random $num_req between 1 and array count I'll need to
check if I've to use array_rand() ou shuffle()? It seems so stupid...

On the other hand, if this change will remain it need to be fixed
anyway: there's no sense in allow array count in $num_req - it returns
the array unchanged with no warnings. In this case this parameter should
receive a value less than the array count. And it should be nice to have
shuffle() use recommendation in the warning if $num_req is equal to
array count.

BTW, the manual notes about this array_rand() change is very very very
incomprehensive.

Reproduce code:
---------------
<?php

$array = range('a', 'z');

foreach (array_rand($array, count($array)) as $key) {
    print $array[$key];
}

?>

Expected result:
----------------
MAYBE: frkzmnvuyiptdcsewbxgjqhloa

Actual result:
--------------
ALWAYS: abcdefghijklmnopqrstuvwxyz


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


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

Reply via email to