#25811 [NEW]: version_compare fails on some versions

From: Date: Thu, 09 Oct 2003 20:08:39 +0000
Subject: #25811 [NEW]: version_compare fails on some versions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-48775@lists.php.net to get a copy of this message
From: pmateescu at novosadhayes dot com Operating system: Windows XP PHP version: 4.3.2 PHP Bug Type: PHP options/info functions Bug description: version_compare fails on some versions Description: ------------ version_compare seems to return invalid results in two cases: 0.1a vs 0.1 and 1.0.a vs 1.0. in both cases the value on the left should be the newest version. If the a (alpha) is confusing it, then it does the same for other letters (e.g. M). Reproduce code: --------------- $test = array ( array('0.1', '0.1', 0), array('0.1', '0.2', -1), array('0.3', '0.2', 1), array('0.1.0', '0.1', 1), array('0.1a', '0.1', 1), array('0.1m', '0.1', 1), array('0.1z', '0.1', 1), array('0.1a', '0.1b', -1), array('0.1.a', '0.1', 1), array('0.1.a', '0.1.b', -1), array('0.1-pre2', '0.1-pre1', 1), array('0.11', '0.2', 1), array('0.11.1', '0.2.3', 1) ); foreach($test as $vals) { $ret = version_compare($vals[0], $vals[1]); echo "$vals[0] vs $vals[1] should be $vals[2] and is $ret ...[". ($ret === $vals[2] ? 'PASSED' : 'FAILED') ."]\n"; } Expected result: ---------------- all of them should return PASSED. Actual result: -------------- 0.1 vs 0.1 should be 0 and is 0 ...[PASSED] 0.1 vs 0.2 should be -1 and is -1 ...[PASSED] 0.3 vs 0.2 should be 1 and is 1 ...[PASSED] 0.1.0 vs 0.1 should be 1 and is 1 ...[PASSED] 0.1a vs 0.1 should be 1 and is -1 ...[FAILED] 0.1m vs 0.1 should be 1 and is -1 ...[FAILED] 0.1z vs 0.1 should be 1 and is -1 ...[FAILED] 0.1a vs 0.1b should be -1 and is -1 ...[PASSED] 0.1.a vs 0.1 should be 1 and is -1 ...[FAILED] 0.1.a vs 0.1.b should be -1 and is -1 ...[PASSED] 0.1-pre2 vs 0.1-pre1 should be 1 and is 1 ...[PASSED] 0.11 vs 0.2 should be 1 and is 1 ...[PASSED] 0.11.1 vs 0.2.3 should be 1 and is 1 ...[PASSED] -- Edit bug report at http://bugs.php.net/?id=25811&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25811&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25811&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25811&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25811&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25811&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25811&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25811&r=support Expected behavior: http://bugs.php.net/fix.php?id=25811&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25811&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25811&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25811&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25811&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25811&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25811&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25811&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=25811&r=float

« previous php.bugs (#48775) next »