Req #54968 [Bgs]: arsort

From: Date: Wed, 01 Jun 2011 15:58:21 +0000
Subject: Req #54968 [Bgs]: arsort
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161108@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54968&edit=1

 ID:                 54968
 Updated by:         rasmus@php.net
 Reported by:        jens at freude-now dot de
 Summary:            arsort
 Status:             Bogus
 Type:               Feature/Change Request
 Package:            Arrays related
 Operating System:   OS X 10.6
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2011-06-01 10:46:28] 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 09:53:23] 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 09:24:17] 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


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



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


Thread (4 messages)

« previous php.bugs (#161108) next »