Skip to content

Disallow version_compare() $operator abbreviations - #6510

Closed
cmb69 wants to merge 3 commits into
php:masterfrom
cmb69:cmb/version-compare
Closed

cmb69 wants to merge 3 commits into
php:masterfrom
cmb69:cmb/version-compare

Conversation

@cmb69

@cmb69 cmb69 commented Dec 12, 2020

Copy link
Copy Markdown
Member

version_compare() does a sloppy check for the $operators argument
which allows arbitrary abbreviations of the supported operators to be
accepted. This is both undocumented and unexpected, and could lead to
subtle BC breaks, if the order of the comparisions will be changed.
Therefore we change to strict comparisons.


Since this comparision behavior is there since PHP 4.3.0 or so, of course, this change would constitute a BC break. Thus I do not actually propose to merge this change, but like to bring that issue to more attention. Maybe we should leave it as is, but document the behavior; maybe we want to get rid of the $operator parameter altogether.

PS: see also https://bugs.php.net/80503

`version_compare()` does a sloppy check for the `$operators` argument
which allows arbitrary abbreviations of the supported operators to be
accepted.  This is both undocumented and unexpected, and could lead to
subtle BC breaks, if the order of the comparisions will be changed.
Therefore we change to strict comparisons.
@kocsismate

Copy link
Copy Markdown
Member

I could happily add this behaviour to the list of deprecations for PHP 8.1, if that works for you.

@cmb69

cmb69 commented Dec 12, 2020

Copy link
Copy Markdown
Member Author

@kocsismate, that's also okay for me, but if we want to deprecate, I'd rather deprecate this parameter altogther. We don't support that for similar functions (e.g. strcmp()) as well, so why there's the need for version_compare()?

@nikic

nikic commented Dec 12, 2020

Copy link
Copy Markdown
Member

This change looks fine to me for master/8.1, with an added/extended test. This was clearly an implementation bug and not intended behavior.

@php-pulls php-pulls closed this in 2b7eb0e Dec 13, 2020
@cmb69
cmb69 deleted the cmb/version-compare branch December 13, 2020 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants