|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75805 Documentation should clarify behavior of version_compare when there are spaces
Submitted: 2018-01-11 23:51 UTC Modified: 2018-06-18 12:20 UTC
From: ksours at internetbrands dot com Assigned:
Status: Verified Package: PHP options/info functions
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ksours at internetbrands dot com
New email:
PHP Version: OS:


 [2018-01-11 23:51 UTC] ksours at internetbrands dot com
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'));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-18 12:20 UTC]
-Status: Open +Status: Verified -Package: Documentation problem +Package: PHP options/info functions
 [2018-06-18 12:20 UTC]
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

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 21:01:31 2024 UTC