1.2.1678. version_compare() Operator

version_compare()’s third argument is checked for its value. The third argument specifies the operator, which may be only one of the following : <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne. The operator is case sensitive.

Until PHP 8.1, it was silently reverted to the default value. It is a deprecated warning in PHP 8.1 and will be finalized in PHP 9.0. It is recommended to fix this parameter in any PHP version.

<?php

// return true
var_dump(version_compare('2.0', '2.1', '<'));

// returns false
var_dump(version_compare('2.0', '2.1', '>'));

// returns NULL and might be interpreted as false
var_dump(version_compare('2.0', '2.1', 'as'));

?>

1.2.1678.2. Connex PHP features

1.2.1678.2.1. Suggestions

  • Use a valid comparison operator

1.2.1678.2.2. Specs

Short name

Php/VersionCompareOperator

Rulesets

All, Analyze, Changed Behavior, CompatibilityPHP81, CompatibilityPHP82

Exakat since

2.3.1

PHP Version

With PHP 8.1 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud