Re: common issue with version_compare()

From: Date: Sat, 21 Jul 2012 03:19:40 +0000
Subject: Re: common issue with version_compare()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-61598@lists.php.net to get a copy of this message
> 1.0.0 and 1.0 are different things. I think the problem is, version numbers are different things to different people - I guess the documentation maybe isn't clear enough on precisely what version numbering scheme it's using. To most people, "1" and "1.0" are the same thing, because they look like decimal-numbers to Americans. The documentation doesn't state how leading zeroes or missing numbers are treated in comparisons. I just submitted a comment with a small script that runs version_compare() on a list of version numbers - 1 lt 1.0 1.0 eq 1.00 1.00 lt 1.01 1.01 eq 1.1 1.1 lt 1.10 1.10 gt 1.10b 1.10b lt 1.10.0 I was a bit surprised at some of these, but they make sense now that I can see how the version-number interpretation works... On Fri, Jul 20, 2012 at 5:07 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote: > Hi! > > >> For example, I was not the only one who found it odd that "1.0" is > >> considered less than "1.0.0" - wouldn't it make sense to > >> "pad" the > shortest > >> version-number with zeroes? e.g. "1.0" if compared against "1.0.0" > would be > >> padded with zeroes at the end, e.g. as "1.0.0". > > 1.0.0 and 1.0 are different things. If you want to make a comparison > that takes into account only two components, you can just cut them both > to two components, then compare. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 >

« previous php.internals (#61598) next »