From:             bert at becoded dot be
Operating system: 
PHP version:      5.4.5
Package:          SPL related
Bug Type:         Feature/Change Request
Bug description:Add sort flag to ArrayObject::ksort

Description:
------------
When mixing numeric and strings for the keys, you can get unexpected
results. With the ksort, you can specify a sort flag (see the flags on
http://www.php.net/manual/en/function.sort.php). Using that, you are able
to change the sort behaviour.
It would be great if we could specify the same sort flag for
ArrayObject::ksort.
So instead of public void ArrayObject::ksort ( void ) it would be public
void ArrayObject::ksort ( [ int $sort_flags = SORT_REGULAR ])

Test script:
---------------
<?php
$list = array('key_3' => 'Value 3', 'Unknown key 1', 'key_1' => 'Value 1',
'key_2' => 'Value 2', 'key_0' => 'Value 0', 'Unknown key 2');
ksort($list);
var_dump($list);
ksort($list, SORT_STRING);
var_dump($list);

$list = new ArrayObject();
$list->offsetSet('key_3', 'Value 3');
$list->append('Unknown key 1');
$list->offsetSet('key_1', 'Value 1');
$list->offsetSet('key_2', 'Value 2');
$list->offsetSet('key_0', 'Value 0');
$list->append('Unknown key 2');
$list->ksort();
//$list->ksort(SORT_STRING);
var_dump($list);

Expected result:
----------------
If $list->ksort(SORT_STRING) would work, then I would expect
object(ArrayObject)[1689]
  string 'Unknown key 1' (length=13)
  string 'Unknown key 2' (length=13)
  public 'key_0' => string 'Value 0' (length=7)
  public 'key_1' => string 'Value 1' (length=7)
  public 'key_2' => string 'Value 2' (length=7)
  public 'key_3' => string 'Value 3' (length=7)



Actual result:
--------------
//ksort
array (size=6)
  'key_0' => string 'Value 0' (length=7)
  'key_1' => string 'Value 1' (length=7)
  0 => string 'Unknown key 1' (length=13)
  'key_2' => string 'Value 2' (length=7)
  'key_3' => string 'Value 3' (length=7)
  1 => string 'Unknown key 2' (length=13)

//ksort with sort flag SORT_STRING
array (size=6)
  0 => string 'Unknown key 1' (length=13)
  1 => string 'Unknown key 2' (length=13)
  'key_0' => string 'Value 0' (length=7)
  'key_1' => string 'Value 1' (length=7)
  'key_2' => string 'Value 2' (length=7)
  'key_3' => string 'Value 3' (length=7)

//ArrayObject::ksort
object(ArrayObject)[1689]
  public 'key_0' => string 'Value 0' (length=7)
  public 'key_1' => string 'Value 1' (length=7)
  string 'Unknown key 1' (length=13)
  public 'key_2' => string 'Value 2' (length=7)
  public 'key_3' => string 'Value 3' (length=7)
  string 'Unknown key 2' (length=13)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=62840&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62840&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62840&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62840&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62840&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62840&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62840&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62840&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62840&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62840&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62840&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62840&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62840&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62840&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62840&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62840&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62840&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62840&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62840&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62840&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62840&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62840&r=mysqlcfg

Reply via email to