Doc #73102 [NEW]: Version compare is just broken.
| From: | greg dot chandler at wellsfargo dot com | Date: | Fri, 16 Sep 2016 22:52:56 +0000 |
| Subject: | Doc #73102 [NEW]: Version compare is just broken. | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-13912@lists.php.net to get a copy of this message | ||
From: greg dot chandler at wellsfargo dot com
Operating system: Linux
PHP version: Irrelevant
Package: Unknown/Other Function
Bug Type: Documentation Problem
Bug description:Version compare is just broken.
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 bug report at https://bugs.php.net/bug.php?id=73102&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73102&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73102&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73102&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73102&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73102&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73102&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73102&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73102&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73102&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73102&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73102&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73102&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73102&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73102&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73102&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73102&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73102&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73102&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73102&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73102&r=mysqlcfg