php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54968 arsort
Submitted: 2011-06-01 09:24 UTC Modified: 2011-06-01 17:58 UTC
From: jens at freude-now dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.6 OS: OS X 10.6
Private report: No CVE-ID: None
 [2011-06-01 09:24 UTC] jens at freude-now dot de
Description:
------------
---
From manual page: http://www.php.net/function.arsort#Rückgabewerte
---
I expected if I want to sort an empty array that the functions gives back a false because there is nothing to sort. 
But the functions gives back a true.

Test script:
---------------
$t = array();
echo '<pre>count($t) ::';
print_r( count($t));
echo '</pre>';

if(arsort($t)) {
    echo '<pre>$t ::';
    print_r( $t);
    echo '</pre>';
}


Expected result:
----------------
false

Actual result:
--------------
true

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-01 09:53 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-06-01 09:53 UTC] rasmus@php.net
Sorting 0 elements is not a failure case. It is perfectly valid for an array to 
have no elements and for this case to not cause a problem in the code. Otherwise 
you would always have to check the number of elements in the array before trying 
to sort it if you want to avoid errors.
 [2011-06-01 10:46 UTC] jens at freude-now dot de
mmh, imagine we, you and me, want to sort the coins in our pocket. But we don't have any coins. Can you sort it? I can't.
 [2011-06-01 17:58 UTC] rasmus@php.net
Of course I can. My array of 0 coins is perfectly sorted. There are no coins out 
of order. By your argument the function should also fail if you have 1 coin since 
that is another case where your coins are already sorted and the function has 
nothing to do.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC