go to bug id or search bugs for
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
echo version_compare('1.0.0', '1.0.0ptotalgarbage');
Add a Patch
Add a Pull Request
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
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.
> '1.0.0ptotalgarbage' is treated as '1.0.0.p.…', […]
That's not correct. Actually, it is treated as
> "any string not found in this list"
The current implementation does not check the full strings, but
rather the beginning of the string only. In this case, it sees
'p' and totally ignores 'totalgarbage'. Frankly, I don't know
whether it is supposed to work this way.