Doc #73102 [Com]: Version compare is just broken.
| From: | greg dot chandler at wellsfargo dot com | Date: | Fri, 16 Sep 2016 22:54:08 +0000 |
| Subject: | Doc #73102 [Com]: Version compare is just broken. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13913@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73102&edit=1
ID: 73102
Comment by: greg dot chandler at wellsfargo dot com
Reported by: greg dot chandler at wellsfargo dot com
Summary: Version compare is just broken.
Status: Open
Type: Documentation Problem
Package: Unknown/Other Function
Operating System: Linux
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I do have sample code on how this is supposed to work if it's needed.
Previous Comments:
------------------------------------------------------------------------
[2016-09-16 22:52:53] greg dot chandler at wellsfargo dot com
Description:
------------
The check should be >= on numeric, and = on alpha when checking.
When alphas are in the versions, the strings are not even compared.
Test script:
---------------
<?php
Function check_versions ($compare, $against)
{
#### $VER_TO_COMPARE $VER_TO_COMPARE_AGAINST
$bad_chars = array ( "-", "_", ".", "/", "(",
")" );
$compare = strtolower(str_replace($bad_chars, ".", $compare));
$against = strtolower(str_replace($bad_chars, ".", $against));
if ( version_compare($compare, $against, '>=') )
{
echo "Current: " . $compare . " Against: " . $against . "
";
return "Pass";
}
else
{
echo "Current: " . $compare . " Against: " . $against . "
";
return "Fail";
}
}
echo check_versions("123456abc123de78z9y0", "123456abc123de78z9y0") .
"\n";
echo check_versions("123456abc123de78z9y0", "123466abc123de78z9y0") .
"\n";
echo check_versions("123466abc123de78z9y0", "123466abc123de78z9y0") .
"\n";
echo check_versions("123466abc123de78z9y0", "123466abd123de78z9y0") .
"\n";
echo check_versions("123466abd123de78z9y0", "123466abc123de78z9y0") .
"\n";
?>
Expected result:
----------------
bash-4.1$ php /tmp/data/1.php
Current: 123456.abc.123.de.78.z.9.y.0 Against: 123456.abc.123.de.78.z.9.y.0 Pass
Current: 123456.abc.123.de.78.z.9.y.0 Against: 123466.abc.123.de.78.z.9.y.0 Fail
Current: 123466.abc.123.de.78.z.9.y.0 Against: 123466.abc.123.de.78.z.9.y.0 Pass
Current: 123466.abc.123.de.78.z.9.y.0 Against: 123466.abd.123.de.78.z.9.y.0 Fail
Current: 123466.abd.123.de.78.z.9.y.0 Against: 123466.abc.123.de.78.z.9.y.0 Pass
Actual result:
--------------
bash-4.1$ php /tmp/data/1.php
Current: 123456.abc.123.de.78.z.9.y.0 Against: 123456.abc.123.de.78.z.9.y.0 Pass
Current: 123456.abc.123.de.78.z.9.y.0 Against: 123466.abc.123.de.78.z.9.y.0 Fail
Current: 123466.abc.123.de.78.z.9.y.0 Against: 123466.abc.123.de.78.z.9.y.0 Pass
Current: 123466.abc.123.de.78.z.9.y.0 Against: 123466.abd.123.de.78.z.9.y.0 Pass
Current: 123466.abd.123.de.78.z.9.y.0 Against: 123466.abc.123.de.78.z.9.y.0 Pass
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73102&edit=1