version_compare operator restrictions
In PHP 8.1, the
version_compare() function is made more strict with the operator parameter.
In PHP 8.1, this is further restricted to disallow partial values for operator parameter.
version_compare(1, 2, ''); version_compare(1, 2, '!'); version_compare(1, 2, 'g'); version_compare(1, 2, 'l'); version_compare(1, 2, 'n');
All of the statements above are were allowed in PHP 8.0, and are no longer allowed in PHP 8.1. These values are undocumented values from the documentation.
Note that PHP 8.0 started to throw
TypeErrorfor all invalid values. The operators disallowed in PHP 8.1 are due to internal partial matching changes.
In PHP 8.1, only the following operators are allowed:
Backwards Compatibility Impact
PHP 8.0 started to disallow a vast majority of disallowed values, and this change in PHP 8.1 is a continuation of it. The disallowed values were not documented.
Using the correct values fixes the issue for all PHP versions.