php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21611 Problem with version_compare() and 'p' suffix (pl == p)
Submitted: 2003-01-13 04:23 UTC Modified: 2003-08-05 07:35 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: jan at horde dot org Assigned:
Status: Closed Package: PHP options/info functions
PHP Version: 4CVS-2003-01-13 (stable) OS: Any
Private report: No CVE-ID: None
 [2003-01-13 04:23 UTC] jan at horde dot org
Either PEAR (1.0.1) fails in calculating release numbers or the apd maintainers chose an invalid release number:

$ pear list
[...]
| apd            | 0.4p1   | stable |
[...]

$ pear list-upgrades
AVAILABLE UPGRADES (STABLE):
============================
+---------+---------+------+
| PACKAGE | VERSION | SIZE |
| apd     | 0.4     | 39kB |
+---------+---------+------+

$ pear upgrade apd
downloading apd-0.4p1.tgz ...
...done:  bytes
upgrade to a newer version (0.4p1 is not newer than 0.4p1)

$ pear upgrade-all

RELEASE WARNINGS
================
+---+
| w |
+---+

w
downloading apd-0.4p1.tgz ...
...done: p39,605 bytes
upgrade to a newer version (0.4p1 is not newer than 0.4p1)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-28 04:02 UTC] arnaud@php.net
Assigning to georges
 [2003-07-24 02:42 UTC] meebey@php.net
this problem still exists, I just reproduced it with my current SmartIRC release Net_SmartIRC-0.5.5p1

it's installed and when I do pear list-upgrades:
meebey-mobile:/db/mysql/mysql# pear list-upgrades
Available Upgrades (stable):
============================
Package      Version Size  
Net_SmartIRC 0.5.5   183kB 

it shows me the older unpatched 0.5.5 version.
So of course pear upgrade-all tries to upgrade and I get:
meebey-mobile:/db/mysql/mysql# pear upgrade-all

Release Warnings
================
w 

w
downloading Net_SmartIRC-0.5.5p1.tgz ...
...done: 186,781 bytes
upgrade to a newer version (0.5.5p1 is not newer than 0.5.5p1)

I think the pear cli should check if the version has a suffix, if so, then it's newer then just the versionnumber...

 [2003-07-31 03:44 UTC] nicos@php.net
PEAR is using STANDARD PHP versions.

And a PHP version can't have a suffix. Fix your versions name.

Note:

PEAR is using version_compare() to compare the versions. 

See: http://php.net/version_compare

 [2003-07-31 14:16 UTC] 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.

 [2003-07-31 15:19 UTC] 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-08-01 05:40 UTC] 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-08-02 09:35 UTC] 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-02 10:03 UTC] et@php.net
reclassifying as PHP options/info functions
 [2003-08-05 07:35 UTC] sniper@php.net
Patch committed.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC