#21611 [Opn]: Problem with version_compare() (Was: Problem with pear cli and release numbers)

From: Date: Sat, 02 Aug 2003 15:03:19 +0000
Subject: #21611 [Opn]: Problem with version_compare() (Was: Problem with pear cli and release numbers)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-45225@lists.php.net to get a copy of this message
 ID:               21611
 Updated by:       et@php.net
-Summary:          Problem with pear cli and release numbers
 Reported By:      jan at horde dot org
 Status:           Open
-Bug Type:         PEAR related
+Bug Type:         PHP options/info functions
 Operating System: Any
 PHP Version:      4CVS-2003-01-13 (stable)
 Assigned To:      gschlossnagle
 New Comment:

reclassifying as PHP options/info functions


Previous Comments:
------------------------------------------------------------------------

[2003-08-02 09:35:44] et@php.net

I'd go for B) and change it, since it's easy and the p suffix is quite
common... here's a patch that does it:

Index: versioning.c
===================================================================
RCS file: /repository/php-src/ext/standard/versioning.c,v
retrieving revision 1.15
diff -u -r1.15 versioning.c
--- versioning.c        10 Jun 2003 20:03:39 -0000      1.15
+++ versioning.c        2 Aug 2003 14:28:45 -0000
@@ -90,7 +90,7 @@
 compare_special_version_forms(char *form1, char *form2)
 {
        int found1 = -1, found2 = -1;
-       special_forms_t special_forms[9] = {
+       special_forms_t special_forms[10] = {
                {"dev", 0},
                {"alpha", 1},
                {"a", 1},
@@ -99,6 +99,7 @@
                {"RC", 3},
                {"#", 4},
                {"pl", 5},
+               {"p", 5},
                {NULL, 0},
        };
        special_forms_t *pp;


------------------------------------------------------------------------

[2003-08-01 05:40:08] et@php.net

version_compare does handle suffixes. (see example below) However, p1
is not a valid suffix for this function. So, solutions would be imo:
A) use the pl suffix and document this
B) make version_compare handle pl and p equally

Example script:
<?php
$version[] = "4.0.1pl2";
$version[] = "4.0.1pl1";
$version[] = "4.0.1b";
$version[] = "4.0.1a";
$version[] = "4.0.1p1";
$version[] = "4.0.1";
printf("%10s | %10s | %10s\n", "Version 1", "Version 2", "New
Vers.");
print str_repeat('-',36)."\n";
for ($i = 0, $s = count($version); $i < $s; $i++ ) {
    for ($j = $i; $j < $s; $j++) {
        printf("%10s | %10s | ",$version[$i],$version[$j]);
        $c = version_compare($version[$i], $version[$j]);
        switch ($c) {
        case -1:
            $r = $version[$j];
        break;
        case 0:
            $r = 'equal';
        break;
        case 1:
            $r = $version[$i];
        }
        printf("%10s\n", $r);
    }
}
?>

Result:
 Version 1 |  Version 2 |  New Vers.
------------------------------------
  4.0.1pl2 |   4.0.1pl2 |      equal
  4.0.1pl2 |   4.0.1pl1 |   4.0.1pl2
  4.0.1pl2 |     4.0.1b |   4.0.1pl2
  4.0.1pl2 |     4.0.1a |   4.0.1pl2
  4.0.1pl2 |    4.0.1p1 |   4.0.1pl2
  4.0.1pl2 |      4.0.1 |   4.0.1pl2
  4.0.1pl1 |   4.0.1pl1 |      equal
  4.0.1pl1 |     4.0.1b |   4.0.1pl1
  4.0.1pl1 |     4.0.1a |   4.0.1pl1
  4.0.1pl1 |    4.0.1p1 |   4.0.1pl1
  4.0.1pl1 |      4.0.1 |   4.0.1pl1
    4.0.1b |     4.0.1b |      equal
    4.0.1b |     4.0.1a |     4.0.1b
    4.0.1b |    4.0.1p1 |     4.0.1b
    4.0.1b |      4.0.1 |      4.0.1
    4.0.1a |     4.0.1a |      equal
    4.0.1a |    4.0.1p1 |     4.0.1a
    4.0.1a |      4.0.1 |      4.0.1
   4.0.1p1 |    4.0.1p1 |      equal
   4.0.1p1 |      4.0.1 |      4.0.1
     4.0.1 |      4.0.1 |      equal



------------------------------------------------------------------------

[2003-07-31 15:19:07] cellog@php.net

Um, PHP version 5.0.0b1 is a PHP version with a suffix.  I'd call this
a valid bug, especially because this can be fixed by using
strnatcasecmp() instead of version_compare().  Perhaps this is a bug in
version_compare(), and should be noted as such?

Greg

------------------------------------------------------------------------

[2003-07-31 14:50:16] nicos@php.net

Yes many developers have this problem because of lack of
documentation.

Opening back as a documentation problem (even if we don't have this
category for PEAR and btw we should have more categories for PEAR).

Can anyone write a little <para> on this? 

------------------------------------------------------------------------

[2003-07-31 14:16:24] meebey@php.net

this should be then at least noted in the PEAR developer
documenation... My package is not the first one with this problem....
(and using p1 as suffix is pretty standard for software versions) so
that note is needed.


------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/21611

-- 
Edit this bug report at http://bugs.php.net/?id=21611&edit=1



Thread (1 message)

  • et@php.net
  • Unknown Message
    • et@php.net
« previous php.bugs (#45225) next »