php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ksours at internetbrands dot com
New email:
PHP Version: OS:

 

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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-18 12:20 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: Documentation problem +Package: PHP options/info functions
 [2018-06-18 12:20 UTC] cmb@php.net
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>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 17:01:32 2024 UTC