Bug #75806 [Nab]: version_compare does strange things with string starting with "p"

From: Date: Fri, 12 Jan 2018 22:46:39 +0000
Subject: Bug #75806 [Nab]: version_compare does strange things with string starting with "p"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213517@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75806&edit=1 ID: 75806 User updated by: ksours at internetbrands dot com Reported by: ksours at internetbrands dot com Summary: version_compare does strange things with string starting with "p" Status: Not a bug Type: Bug Package: PHP options/info functions PHP Version: 7.0.27 Assigned To: cmb Block user comment: N Private report: N New Comment: This behavior is entirely unclear from the documentation, which I read in detail before reporting and again just now. It appears that the strings in the comparison list are treated as separate "parts" even if then occur within a larger non numeric string, but this is not mentioned anywhere and not clear. Especially since it explicitly states that unrecognized strings in the version are handled: "any string not found in this list" Actually poking it further there is some really unintuitive and undocumented behavior in how longer strings that contain the "known" version parts get interpreted in general: version_compare('1.0.0xdev', '1.0.0xxxdevxxx'); // returns 0 version_compare('1.0.0xdev', '1.0.0xxxdev-xxx'); // returns 1 If this isn't a bug, then the documentation is inadequate. Previous Comments: ------------------------------------------------------------------------ [2018-01-12 22:24:28] cmb@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php '1.0.0ptotalgarbage' is treated as '1.0.0.p.…', which is higher than '1.0.0'. ------------------------------------------------------------------------ [2018-01-12 00:21:07] ksours at internetbrands dot com Description: ------------ version_compare appears to treat any string starting with p at the pl=p level when doing comparisons, which is contrary to the documented behavior Test script: --------------- echo version_compare('1.0.0', '1.0.0ptotalgarbage'); Expected result: ---------------- 1 Actual result: -------------- -1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75806&edit=1

« previous php.bugs (#213517) next »