Doc #75805 [Opn->Ver]: Documentation should clarify behavior of version_compare when there are spaces
| From: | cmb@php.net | Date: | Mon, 18 Jun 2018 12:20:49 +0000 |
| Subject: | Doc #75805 [Opn->Ver]: Documentation should clarify behavior of version_compare when there are spaces | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15790@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75805&edit=1
ID: 75805
Updated by: cmb@php.net
Reported by: ksours at internetbrands dot com
Summary: Documentation should clarify behavior of
version_compare when there are spaces
-Status: Open
+Status: Verified
Type: Documentation Problem
-Package: Documentation problem
+Package: PHP options/info functions
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Since version_compare() is supposed to compare two
"PHP-standardized" version number strings (which do not contain
any whitespace), and since the function behaves like described as
of PHP 4.3 at least[1], this is indeed not a bug but rather a doc
issue.
[1] <https://3v4l.org/v0bOF#v430>
Previous Comments:
------------------------------------------------------------------------
[2018-01-11 23:51:41] ksours at internetbrands dot com
Description:
------------
I'm not 100% sure if this is a documentation problem or a code problem but the documentation
doesn't quite match the behavior so one of them is wrong. Since the function behavior
isn't clearly wrong I'm going with doc.
On "version_compare" it says:
"Then it compares the parts starting from left to right. If a part contains special version
strings these are handled in the following order: any string not found in this list < dev <
alpha = a < beta = b < RC = rc < # < pl = p."
If there is a space in the version string this gets incorporated into the "special string"
and thus the string will always fall under "any string not found in this list" even if it
appears to match. You can work this out from the transformations described but it's *not*
intuitive and should be explicitly called out (or the function behavior changed to handle spaces)
Test script:
---------------
//these will all return "equal" results which is not what is immediately expected
var_dump(version_compare('1.0.0 alpha 1', '1.0.0 beta 1'));
var_dump(version_compare('1.0.0 dev 1', '1.0.0 beta 1'));
var_dump(version_compare('1.0.0 totalgarbage 1', '1.0.0 beta 1'));
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75805&edit=1