From: benjamin dot lewis at samail dot net
Operating system: redhat
PHP version: 4.3.7
PHP Bug Type: Arrays related
Bug description: stange str comparing results
Description:
------------
cases length and value give the expected results, but when mixed in the
case of length_and_value it gives unexpected results.
Sorry for posting more than 20 lines i don't have an open server to post
it to.
Ben
Reproduce code:
---------------
<?php
$doesntwork = array(
'd1_b_000_000_0_b_000_001_0_b_000_001_0',
'd1_b_000_000_0_b_000_001_0_b_001_001_0',
'd1_b_000_000_0_b_000_001_0_b_000_002_0',
'd1_b_000_000_0_b_000_001_0_b_001_002_0',
'd1_b_000_000_0_b_000_001_0_b_001_003_0',
'd1_b_000_000_0_b_000_001_0_b_000_004_0_b_000_000_0',
'd1_b_000_000_0_b_000_001_0_b_000_004_0_b_000_001_0',
'd1_b_000_000_0_b_000_001_0_b_000_004_0_b_000_002_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_000_001_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_002_001_0_b_000_000_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_002_001_0_b_000_001_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_002_001_0_b_000_002_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_000_002_0' ,
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_002_002_0_b_000_000_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_002_002_0_b_000_001_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_002_002_0_b_000_002_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_000_003_0',
'd1_b_000_000_0_b_000_001_0_b_000_005_0_b_000_001_0_b_000_004_0'
);
function value($a, $b)
{
if($a < $b) return -1;
else return 1;
}
function length($a, $b)
{
if(strlen($a) < strlen($b)) return -1;
else return 1;
}
function length_and_value($a, $b)
{
if(strlen($a) < strlen($b) || $a < $b) return -1;
else return 1;
}
if(is_array($doesntwork))
{
foreach($doesntwork as $id) echo '<br>'.$id;
echo '<hr>';
usort($doesntwork, 'length');
foreach($doesntwork as $id) echo '<br>'.$id;
echo '<hr>';
usort($doesntwork, 'value');
foreach($doesntwork as $id) echo '<br>'.$id;
echo '<hr>';
usort($doesntwork, 'length_and_value');
foreach($doesntwork as $id) echo '<br>'.$id;
echo '<hr>';
}
?>
--
Edit bug report at http://bugs.php.net/?id=29907&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29907&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29907&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29907&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=29907&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29907&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29907&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29907&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29907&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29907&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29907&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29907&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29907&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29907&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29907&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29907&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29907&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29907&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29907&r=float