Skip to content
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

QA: use strict comparisons #404

Merged
merged 1 commit into from
Oct 22, 2020
Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 21, 2020

Strict type comparisons should be used as a rule, with loose type comparisons being the exception.

This is especially important when comparing variables which are expected to be strings, as when one of the two operands - for whatever reason - is not a string, the other operand will be juggled to the type of the first operand which can lead to unexpected results and hard to debug bugs.

For array functions which do loose type comparisons, setting the third $strict parameter to false can be seen as a clear indication that this is a conscious, well thought out decision by the developer.
In all other cases, $strict true should be used.

Refs:

Strict type comparisons should be used as a rule, with loose type comparisons being the exception.

This is especially important when comparing variables which are expected to be strings, as when one of the two operands - for whatever reason - is not a string, the other operand will be juggled to the type of the first operand which can lead to unexpected results and hard to debug bugs.

For array functions which do loose type comparisons, setting the third `$strict` parameter to `false` can be seen as a clear indication that this is a conscious, well thought out decision by the developer.
In all other cases, `$strict` `true` should be used.

Refs:
* http://phpcheatsheets.com/compare/equal/
* http://php.net/manual/en/function.in-array.php
@jrfnl jrfnl added this to the 1.7.1 milestone Oct 21, 2020
@schlessera schlessera merged commit f049919 into master Oct 22, 2020
@schlessera schlessera deleted the feature/cs-use-strict-comparisons branch October 22, 2020 09:15
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.

2 participants