|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-01-12 00:21 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 18:00:01 2025 UTC |
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.