#25811 [Opn->Bgs]: version_compare fails on some versions

From: Date: Mon, 13 Oct 2003 06:58:31 +0000
Subject: #25811 [Opn->Bgs]: version_compare fails on some versions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-48897@lists.php.net to get a copy of this message
ID: 25811 Updated by: sniper@php.net Reported By: pmateescu at novosadhayes dot com -Status: Open +Status: Bogus Bug Type: PHP options/info functions Operating System: Windows XP PHP Version: 4.3.2 New Comment: RTFM: version_compare -- Compares two "PHP-standardized" version number strings. Notice the "PHP-standardized" there. There is no bug here, 0.1 > 0.1x where x == a-z Previous Comments: ------------------------------------------------------------------------ [2003-10-09 16:08:39] pmateescu at novosadhayes dot com 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 this bug report at http://bugs.php.net/?id=25811&edit=1

« previous php.bugs (#48897) next »