Ask a Question related to PHP Development, Design and Development.
-
et@php.net #1
#21611 [Opn]: Problem with version_compare() (Was: Problem with pear cli and release numbers)
ID: 21611
Updated by: [email]et@php.net[/email]
-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] [email]et@php.net[/email]
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] [email]et@php.net[/email]
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] [email]cellog@php.net[/email]
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] [email]nicos@php.net[/email]
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] [email]meebey@php.net[/email]
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
[url]http://bugs.php.net/21611[/url]
--
Edit this bug report at [url]http://bugs.php.net/?id=21611&edit=1[/url]
et@php.net Guest
-
PEAR XML RSS problem
Hi guys I hope someone can help, Using http://www.stargeek.com/php_scripts.php?script=1 as a basis and using the PEAR XML_RSS parser... -
AW: [PHP] pear problem
Hi, yes, the directory the /usr/php/pear/share/pear is included, the error message is: Warning: main(PEAR.php): failed to open stream: No such... -
pear problem
I've a problem with pear, only the DB.php and the Mail.php are working, all the others I installed don't work. Installed packages:... -
#21611 [Opn->Csd]: Problem with version_compare() and 'p' suffix (pl == p)
ID: 21611 Updated by: sniper@php.net Reported By: jan at horde dot org -Status: Open +Status: Closed... -
[PHP-DEV] Patch for version_compare() to fix bug #21611
--tKW2IUtsqtDRztdT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, Attached is a patch that makes...



Reply With Quote

