.. _structures-booleanstrictcomparison: .. _strict-comparison-with-booleans: Strict Comparison With Booleans +++++++++++++++++++++++++++++++ Strict comparisons prevent mistaking an `error `_ with a false. Boolean values may be easily mistaken with other values, especially when the function may return integer or boolean as a normal course of action. It is encouraged to use strict comparison === or !== when booleans are involved in a comparison. `switch() `_ structures always uses `==` comparisons. Since PHP 8.0, it is possible to use `match() `_ to have strict comparisons. This is not reported by this analysis, as every switch should be refactored. Native functions `in_array() `_, `array_keys() `_ and `array_search() `_ have a third parameter to make it use strict comparisons. .. code-block:: php Connex PHP features ------------------- + `strict-comparison `_ + `switch `_ + `match `_ Suggestions ___________ * Use strict comparison whenever possible Specs _____ +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Short name | Structures/BooleanStrictComparison | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`CE `, :ref:`CI-checks `, :ref:`Changed Behavior `, :ref:`Suggestions ` | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 0.8.4 | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-phinx-structures-booleanstrictcomparison`, :ref:`case-typo3-structures-booleanstrictcomparison` | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Community Edition `_, `Exakat Cloud `_ | +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+