Skip to content

Disallow version_compare() $operator abbreviations #6510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Dec 12, 2020

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
Member

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

@cmb69
Copy link
Member Author

cmb69 commented Dec 12, 2020

@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
Copy link
Member

nikic commented Dec 12, 2020

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