Andrew Faulds | 20 Jul 2012 22:57
Gravatar

Re: [PHP-DEV] common issue with version_compare()

Well, in the spirit of PHP, let's make version_compare_fixed()!
On Jul 20, 2012 1:41 PM, "Rasmus Schultz" <rasmus <at> mindplay.dk> wrote:

> From the comments in the documentation, it seems others are having the same
> problem with version_compare() that I was running into:
>
> http://us2.php.net/version_compare
>
> Look at all those code-samples and "extensions" to the function - I found
> it very odd that the documentation does not explain how an "empty"
> version-number is interpreted compared to the strings and numbers, which
> are clearly defined and explained.
>
> 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".
>
> Of course that would break backwards compatibility, which kind of defeats
> the purpose of having a standardized version-number comparison standard.
> But as you can see, people aren't using the function as-is anyway - they're
> writing their own...
>
> - Rasmus Schultz
>
Stas Malyshev | 20 Jul 2012 23:07
Favicon
Gravatar

Re: [PHP-DEV] common issue with version_compare()

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

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Hartmut Holzgraefe | 21 Jul 2012 00:22
Picon

Re: [PHP-DEV] common issue with version_compare()

On 07/20/2012 11:07 PM, Stas Malyshev wrote:
> 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.

it is hart to imagine a 1.0 followed by 1.0.0 in real world, but
the only reason for something like this that i can come up with
is that, for whatever reason, a project wants to change from
two component version numbers to three component ones right after
having done a 1.0. And in that case a 1.0.0 following the 1.0
would be a new release, even if it only differs by the extra .0

And so 1.0 < 1.0.0 would be perfectly correct.

-- 
hartmut

--

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Simon J Welsh | 21 Jul 2012 00:38
Picon
Gravatar

Re: [PHP-DEV] common issue with version_compare()


On 21/07/2012, at 10:22 AM, Hartmut Holzgraefe wrote:

> On 07/20/2012 11:07 PM, Stas Malyshev wrote:
>> 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.
> 
> it is hart to imagine a 1.0 followed by 1.0.0 in real world, but
> the only reason for something like this that i can come up with
> is that, for whatever reason, a project wants to change from
> two component version numbers to three component ones right after
> having done a 1.0. And in that case a 1.0.0 following the 1.0
> would be a new release, even if it only differs by the extra .0
> 
> And so 1.0 < 1.0.0 would be perfectly correct.
> 
> -- 
> hartmut

I've had to use two digit version numbers when upgrading frameworks during
the 5.4 development phrase. This meant that version_compare('5.4', PHP_VERSION);
would return -1 for things like 5.4.0-beta1. Padding the 5.4 to 5.4.0 would've
broken the comparison, as well as changing the return value of
version_compare('5.4', PHP_VERSION); when running 5.4.0.
---
Simon Welsh
Admin of http://simon.geek.nz/

--

-- 
(Continue reading)

Rasmus Schultz | 21 Jul 2012 05:19
Picon
Gravatar

Re: [PHP-DEV] common issue with version_compare()

> 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 <at> 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
(Continue reading)

Kris Craig | 21 Jul 2012 08:22
Picon
Gravatar

Re: [PHP-DEV] common issue with version_compare()

>     1.01 eq 1.1

Could you explain this one to me?  In every versioning system I've ever
used, 1.1 would be greater than 1.01, not equal.

> On Fri, Jul 20, 2012 at 5:07 PM, Stas Malyshev <smalyshev <at> 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
> >
Andrew Faulds | 21 Jul 2012 09:52
Gravatar

Re: [PHP-DEV] common issue with version_compare()

Yeah, that would definitely be a bug.
On Jul 21, 2012 7:23 AM, "Kris Craig" <kris.craig <at> gmail.com> wrote:

> >     1.01 eq 1.1
>
> Could you explain this one to me?  In every versioning system I've ever
> used, 1.1 would be greater than 1.01, not equal.
>
> > On Fri, Jul 20, 2012 at 5:07 PM, Stas Malyshev <smalyshev <at> 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
> > >
>
(Continue reading)

Tjerk Meesters | 21 Jul 2012 11:46
Picon
Gravatar

Re: [PHP-DEV] common issue with version_compare()


On 21 Jul, 2012, at 2:22 PM, Kris Craig <kris.craig <at> gmail.com> wrote:

>>    1.01 eq 1.1
> 
> Could you explain this one to me?  In every versioning system I've ever
> used, 1.1 would be greater than 1.01, not equal.

Because 01 is just a padded version of 1, probably used to make it easier for regular string comparisons
(until you reach major version 10). 

> 
>> On Fri, Jul 20, 2012 at 5:07 PM, Stas Malyshev <smalyshev <at> 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/
(Continue reading)

Andrew Faulds | 21 Jul 2012 12:09
Gravatar

Re: [PHP-DEV] common issue with version_compare()

If you think 1.1 =/= 1.01 you're sure using some weird version numbers.
Only 1.0.1 would be smaller.

Has anyone seen these weird version ordering schemes in practise? On any
major projects of note?
On Jul 21, 2012 10:51 AM, "Tjerk Meesters" <tjerk.meesters <at> gmail.com> wrote:

>
>
> On 21 Jul, 2012, at 2:22 PM, Kris Craig <kris.craig <at> gmail.com> wrote:
>
> >>    1.01 eq 1.1
> >
> > Could you explain this one to me?  In every versioning system I've ever
> > used, 1.1 would be greater than 1.01, not equal.
>
> Because 01 is just a padded version of 1, probably used to make it easier
> for regular string comparisons (until you reach major version 10).
>
> >
> >> On Fri, Jul 20, 2012 at 5:07 PM, Stas Malyshev <smalyshev <at> 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
(Continue reading)

Kris Craig | 22 Jul 2012 04:08
Picon
Gravatar

Re: [PHP-DEV] common issue with version_compare()

On Sat, Jul 21, 2012 at 3:09 AM, Andrew Faulds <ajfweb <at> googlemail.com>wrote:

> If you think 1.1 =/= 1.01 you're sure using some weird version numbers.
> Only 1.0.1 would be smaller.
>
> Has anyone seen these weird version ordering schemes in practise? On any
> major projects of note?
>
>
*raises his hand*

1.01 and 1.0.1 are essentially the same thing.  If a versioning model
doesn't utilize the second dot (many don't), then 1.01 would be the same as
1.0.1 in a project that does use it.

The Gitflow model reserves that last digit for hotfixes.  However, many
developers (including myself) drop the second dot as it's pretty much
superfluous.  Maybe that's an American thing,  I dunno.  But having 1.1 ==
1.01 would cause this function to be completely and utterly *worthless *for
many developers like myself.

--Kris
Lester Caine | 22 Jul 2012 09:01
Picon
Favicon
Gravatar

Re: [PHP-DEV] common issue with version_compare()

Kris Craig wrote:
> *raises his hand*
>
> 1.01 and 1.0.1 are essentially the same thing.  If a versioning model
> doesn't utilize the second dot (many don't), then 1.01 would be the same as
> 1.0.1 in a project that does use it.
>
> The Gitflow model reserves that last digit for hotfixes.  However, many
> developers (including myself) drop the second dot as it's pretty much
> superfluous.  Maybe that's an American thing,  I dunno.  But having 1.1 ==
> 1.01 would cause this function to be completely and utterly *worthless *for
> many developers like myself.

Sorry Kris, but the version number system that PHP uses by definition is three 
numbers. We are currently on 5.4.x and the function is defined as
"version_compare() compares two "PHP-standardized" version number strings"
so as far as I am concerned most of this discussion has been irrelevant.

The comment posted to the page is equally in error as only one of the strings 
are in what I would call "PHP-standardized". But the main point here is that the 
function is DESIGNED to allow us to enable and disabled PHP actions based on the 
version number of PHP, so as long as the version numbers are correctly set IN 
PHP then there is nothing wrong with the function? Redefining a function to do a 
job it is not defined for is simply wrong and if you want a function that works 
for a different versioning system, then it's a new function!

--

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
(Continue reading)

Ángel González | 23 Jul 2012 17:29
Picon

Re: [PHP-DEV] common issue with version_compare()

On 22/07/12 04:08, Kris Craig wrote:
> On Sat, Jul 21, 2012 at 3:09 AM, Andrew Faulds <ajfweb <at> googlemail.com>wrote:
>
>> If you think 1.1 =/= 1.01 you're sure using some weird version numbers.
>> Only 1.0.1 would be smaller.
>>
>> Has anyone seen these weird version ordering schemes in practise? On any
>> major projects of note?
>>
>>
> *raises his hand*
>
> 1.01 and 1.0.1 are essentially the same thing. 
No, it is not.

> If a versioning model doesn't utilize the second dot (many don't), then 1.01 would be the same as
> 1.0.1 in a project that does use it.
It's the first time I hear about a project writing 1.0.1 as 1.01

> The Gitflow model reserves that last digit for hotfixes.  However, many
> developers (including myself) drop the second dot as it's pretty much
> superfluous.  Maybe that's an American thing,  I dunno.  But having 1.1 ==
> 1.01 would cause this function to be completely and utterly *worthless *for
> many developers like myself.

It doesn't matter that you bump the minor or revision number, it's up to
each
project what should increase on a change of X severity. It would still
work flawlesslly
as far as you do it consistently.
(Continue reading)

Rasmus Schultz | 22 Jul 2012 03:52
Picon
Gravatar

Re: [PHP-DEV] common issue with version_compare()

using this particular version-numbering scheme, 1.01 is equal to 1.1 - I
don't think that's a bug, because the version-numbers in this
version-numbering scheme are integers, not decimals.

so I believe this is in fact as correct as it can be, since numbers like
"01" should not really be used in this version-numbering scheme, as it's
not an integer.

changing it is probably not a good idea, since comparisons like "1.10" and
"1.100" could potentially become really tricky - in the current
version-numbering scheme, 100 is greater than 10, but if these were
interpreted as decimals, they would be equal.

looks like I opened up pandora's box with this one ;-)

bottom line, I think, is that version_compare() should work for the
version-numbering scheme used by PHP, so that it works for checking the PHP
version-number. if you happen to use the same version-numbering scheme for
your PHP projects, good for you - if you don't, too bad... there are just
too many version-numbering schemes to support them all...

On Sat, Jul 21, 2012 at 2:22 AM, Kris Craig <kris.craig <at> gmail.com> wrote:

>
> >     1.01 eq 1.1
>
> Could you explain this one to me?  In every versioning system I've ever
> used, 1.1 would be greater than 1.01, not equal.
>
> > On Fri, Jul 20, 2012 at 5:07 PM, Stas Malyshev <smalyshev <at> sugarcrm.com
(Continue reading)


Gmane