|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-10-13 02:58 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 19:00:01 2025 UTC |
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]