php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62586 version_compare, case sensitivity
Submitted: 2012-07-17 10:54 UTC Modified: 2012-07-20 02:24 UTC
From: dattaya108 at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.14 OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dattaya108 at gmail dot com
New email:
PHP Version: OS:

 

 [2012-07-17 10:54 UTC] dattaya108 at gmail dot com
Description:
------------
Is this behavior intentional? If so, should the bug type be changed to 'documentation problem'?

Test script:
---------------
var_dump(version_compare('2.1.0-DEV', '2.1.0-dev'));

Expected result:
----------------
bool(false)

Actual result:
--------------
bool(true)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-17 10:58 UTC] dattaya108 at gmail dot com
Is there a page in the documentation that describes what's a "PHP-standardized" version number?
 [2012-07-17 11:09 UTC] dattaya108 at gmail dot com
Wrong test script was provided. Right one:
var_dump(version_compare('2.1.0-DEV', '2.1.0-dev', '<'));
 [2012-07-17 14:53 UTC] laruence@php.net
hmm, you can strtolower before compare, I'd prefer this to be a doc problem..
 [2012-07-18 19:51 UTC] mail+php at requinix dot net
>Is there a page in the documentation that describes what's a "PHP-standardized" 
version number?
The description block gives a fairly precise explanation for how version numbers 
are compared: after a couple character replacements, numeric parts are compared 
as numbers and non-numeric parts (eg, "alpha" and "rc") are compared according 
to a hierarchy.

>hmm, you can strtolower before compare, I'd prefer this to be a doc problem..
The operator parameter says "This parameter is case-sensitive, so values should 
be lowercase". Maybe move that somewhere more obvious, like the description or a 
note?
 [2012-07-19 05:33 UTC] dattaya108 at gmail dot com
Yes, definitely, because without third parameter result is the same:
var_dump(version_compare('2.1.0-DEV', '2.1.0-dev'));
var_dump(version_compare('2.1.0-dev', '2.1.0-dev'));

int(-1)
int(0)
 [2012-07-19 05:44 UTC] dattaya108 at gmail dot com
And this: "This parameter is case-sensitive, so values should 
be lowercase". is probably about the parameter itself:
var_dump(version_compare('2.1.0-dev', '2.1.0-dev', 'lt'));
var_dump(version_compare('2.1.0-dev', '2.1.0-dev', 'LT'));

bool(false)
NULL
 [2012-07-19 14:26 UTC] laruence@php.net
-Type: Bug +Type: Documentation Problem -Package: Unknown/Other Function +Package: *General Issues
 [2012-07-20 02:17 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Package: *General Issues +Package: Documentation problem -Assigned To: +Assigned To: aharvey
 [2012-07-20 02:24 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=326719
Log: Fix doc bug #62586 (version_compare, case sensitivity) by adding a note about
case sensitivity.
 [2012-07-20 02:24 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2012-07-20 02:24 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2012-07-20 06:17 UTC] dattaya108 at gmail dot com
Thank you aharvey!
I was going to propose to change it to something like this
```
Special version strings such as <literal>alpha</literal> and   	     <literal>beta</literal> should be lowercase. Otherwise they will be treated as
<literal>any string not found in this list</literal>.
```
but after a test it turned out that it's not working that way:
var_dump(version_compare('2.1.0-DEV', '2.1.0-dev', '<'));
var_dump(version_compare('2.1.0-ALPHA', '2.1.0-dev', '<'));
var_dump(version_compare('2.1.0-BETA', '2.1.0-dev', '<'));
var_dump(version_compare('2.1.0-RC', '2.1.0-dev', '<'));

bool(true)
bool(true)
bool(true)
bool(false)
 [2012-07-20 06:22 UTC] dattaya108 at gmail dot com
Actually it's working that way, I forget that "RC = rc".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 10:01:31 2024 UTC